Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..
2023-01-10 01:37 PM - edited 2023-01-10 01:48 PM
I am trying to get a value from a field on the form in edit mode. I have read the code below should work but it is always returning null. The end goal is to compare to dates and show warning if start date is after due date. It may be worth noting the field I am trying to get value from is a calculated field but would not recalculate during this code.
Also I can read the startdate just fine.
const duedateId = 23395 ; //
const startdateId = 24173; //
const startbuttonId = 24172; //
const yesId = 152;
const noId = 155;
Sys.Application.add_load(function() {
const statusStartdateId = $CM.getFieldById(startdateId).clientId;
$('div[id^="' + statusStartdateId + '"]').change(function () {
const startdate = $CM.getFieldValue(startdateId);
const duedate = $CM.getFieldValue(duedateId);
alert(duedate);
});
});
2023-01-11 09:15 AM
If you open the needed element via INSPECT feature of a browser, u will see needed element ID. Then u can get the value directly as:
$('#[YOUR_ELEMENT_ID_HERE]').text();
$('#master_DefaultContent_rts_s6172_f21762c').text();
2023-01-11 07:24 AM - edited 2023-01-11 07:24 AM
@matthancock wrote:It may be worth noting the field I am trying to get value from is a calculated field but would not recalculate during this code.
Calc field need direct JQuery pathing, not over $CM.
2023-01-11 09:05 AM
It is on the layout and is calculated.
2023-01-11 09:06 AM
Do you have an example of this?
2023-01-11 09:15 AM
If you open the needed element via INSPECT feature of a browser, u will see needed element ID. Then u can get the value directly as:
$('#[YOUR_ELEMENT_ID_HERE]').text();
$('#master_DefaultContent_rts_s6172_f21762c').text();
2023-01-11 09:18 AM
Ok, I am able to see the following below. Does that id change for environments? Is it okay to hardcode?
2023-01-11 10:41 AM
Well, it does change per environment. If you need consistency between, @DavidPetty provided so:
2023-01-11 02:59 PM
This doesn't work in the case for calculated fields though. It returns the field id but I have to get the element id based on your earlier answer.
2023-01-11 03:22 PM - edited 2023-01-11 03:22 PM
If you get ID, you can make use of wildcards in JQuery.
$('span[id*=f[FIELD_ID]c]').text();