Set Value of a field on the record not available on form once the onload client script runs

Nishant16
Tera Expert

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

9 REPLIES 9

IAmAbhigyaan12
Giga Guru

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

If my answer solved your issue, please mark my answer as Correct & hit like Helpful

Thanks
Abi

Its not a good practice to add GlideRecord in a client script. 

-Anurag

priyasunku
Kilo Sage

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

Anurag Tripathi
Mega Patron
Mega Patron

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.

-Anurag