Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Object returning null for field value

matthancock
Contributor III

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);

});
});

1 ACCEPTED SOLUTION

Accepted Solutions

Anonymous
Not applicable

 

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();

View solution in original post

14 REPLIES 14

DavidPetty
Archer Employee
Archer Employee

@matthancock, is the field on the layout or calculated?

 Advisory Consultant

Anonymous
Not applicable

@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.

It is on the layout and is calculated. 

matthancock_0-1673445908573.png

 

Do you have an example of this?

Anonymous
Not applicable

 

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();

Ok, I am able to see the following below. Does that id change for environments? Is it okay to hardcode?

matthancock_0-1673446679162.png

 

Anonymous
Not applicable

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.

Anonymous
Not applicable

If you get ID, you can make use of wildcards in JQuery. 

 

$('span[id*=f[FIELD_ID]c]').text();