The CreatorCon Call for Content is officially open! Get started here.

How to use variable in encoded query?

Admin7267
Kilo Sage

I don't want to use the hardcoded value of SYS ID in the script. How to store Sys ID and use it in the encoded query in widget?

 

 

 

 if (input && input.action == 'submit' && ritmGr.get(ritmSysId)) {
 var cbt = input.prefTime;
 ritmGr.variables.preferred_callback_time = cbt;
 var gr = new GlideRecord('question_choice');
 gr.addEncodedQuery("question=e91707e01b571110c8f821f72a4bcba4^value=" + cbt);  //Sys ID shouldn't be hardcoded
 gr.query();
 if (gr.next()) {
 ritmGr.comments.setJournalEntry("Callback time has been updated to: " + grQ.getValue('text'));
 }
 new global.Workflow().restartWorkflow(ritmGr, true);
 ritmGr.update();
    }

 

 

 

 

2 REPLIES 2

Samaksh Wani
Giga Sage

Hello @Admin7267 

 

Use like this :-

 

var sysID = e91707e01b571110c8f821f72a4bcba4;
gr.addEncodedQuery("question="+sysID+"^value=" + cbt); 

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

 

 

Prince Arora
Tera Sage

@Admin7267 

 

You can store the sys_id in system property and use the system property while calculations:

 

1) Create a system property (sys_properties.LIST) <-> New  <-> provide a name in it <-> Save

2) Fetch the value from system property as

gs.getProperty("Name_of_the_property");

 

var sys = gs.getProperty("name_of_the_property");
 gr.addEncodedQuery("question=" + sys +"^value=" + cbt);  //Sys ID shouldn't be hardcoded

 

In future if you want to update the value you can directly change into the system property and it will reflect in the code

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.