Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How do I use gr.setValue();?

NOW
Kilo Contributor

Hi,all

I would like to add a process to insert a record into the description field of an incident in a script.
I understand that I can write the script using the following, but there are two things I would like you to tell me.

1) gr.setValue("A", "B"); ⇐ Please let me know if there is a docs URL that explains this expression. I looked for it, but couldn't find it.

2)I'm not sure what I should put in A and B, so please let me know.

 

Best Regard

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage

setValue() is a method in GlideRecord() class. Official document is available in ServiceNow's GlideRecord api reference.

setValue(String name, Object value)

Sets the specified field to the specified value.

Normally a script would do a direct assignment, for example, now_GR.category = value. However, if in a script the element name is a variable, then now_GR.setValue(elementName, value) can be used. When setting a value, ensure the data type of the field matches the data type of the value you enter.

https://developer.servicenow.com/print_page.do?release=paris&category=null&identifier=c_GlideRecordA...

 

View solution in original post

7 REPLIES 7

JerryJ071847183
Tera Sage

gr.setValue('field_name','field_value');

here your A and B are actually what I have mentioned above.

 

Example for reference:

var gr = new GlideRecord('planned_task');

gr.setValue('state', -5);

 

Mark my ANSWER as CORRECT and HELPFUL fi it helps

 

 

Hi NOW,

 

if you need anymore help let me know , else can you Mark my ANSWER as CORRECT if it served your objective

var gr =new gliderecord("incident");

gr.getvalue("state",=-3 );

 

this statement is not working 

jbjhhuhuihn,
There's not "=".
 

 There's not state = -3 by default. "On hold" is 3.

var gr =new gliderecord("incident");

gr.getvalue("state", -3); // there's no "-3" OOTB