Set Value of a field on the record not available on form once the onload client script runs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 01:26 AM
Hi All,
I have a requirement to run Client Script based on a condition that the record field "Is Present" is true then run the client script.
Field "Is Present" is not available on form, so i pass this value to Client script using scratchpad, now once the client script runs i need to set this Field value to false, how can i do this.
if(g_scratchpad.IsPresent)){
var rstate = g_form.getValue("state");
if(rstate.includes("closed")) {
g_form.setReadOnly("state", true);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 01:34 AM
Hi @Nishant16 ,
Could you please check the below mentioned code.
if (g_scratchpad.IsPresent) {
var rstate = g_form.getValue("state");
if (rstate.includes("closed")) {
g_form.setReadOnly("state", true);
// Update the record to set "Is Present" to false
var gr = new GlideRecord('<table_name>');
gr.get(g_form.getUniqueValue());
gr.setValue('Is Present', false);
gr.update();
}
}
Please hit the like button if the solution works for you
Thanks
Abi
Thanks
Abi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 01:45 AM
Its not a good practice to add GlideRecord in a client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 01:40 AM
Hi @Nishant16
you cannot set the field which is not on form through client script. you can perform this update using business rule.
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 01:51 AM
What is the logic behind the field IsPresent? Is it supposed to be false for all closed records?
If so then you can write a BR to do so.