- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2020 03:49 AM
Hi,
I have a requirement to pass the current object from html to processing script.
Here is my code snippet:
HTML:
<g:evaluate var="jvar_taskobj" jelly="true" object="true">
var base_table_name = RP.getWindowProperties().get('sysId');
var gr = new GlideRecord("wm_task");
gr.addQuery('sys_id',base_table_name);
gr.query();
gr.next();
gr;
</g:evaluate>
Processing script:
if ('false' == cancelled) {
var clone = new SMTask().cloneTask(taskobj);
(new StateFlow().processFlow(taskobj, '41dfa2e0d7630100fceaa6859e61035d', 'manual'));
gs.addInfoMessage(gs.getMessage("Cloned from {0}", task_number));
response.sendRedirect("wm_task.do?sys_id=" + clone);
}
How can I pass the current object in the above code "taskobj" is not working.
Thanks
Kevin
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2020 02:59 AM
Hi,
I am referring to the <g:evaluate> tag
I could find in both the g:evaluate tags you are doing query of same table "wm_task" with same sys_id using RP.getWindowProperties().get('sysId')
I could see already hidden element "task_id" which stores the sys_id at the top.
So no need of new hidden element.
you can use that directly in processing script
Try this
if ('false' == cancelled) {
gs.info('Inside sysid is: ' + task_id);
var gr = new GlideRecord('wm_task');
gr.get(task_id);
var clone = new SMTask().cloneTask(gr);
(new StateFlow().processFlow(gr, '41dfa2e0d7630100fceaa6859e61035d', 'manual'));
gs.addInfoMessage(gs.getMessage("Cloned from {0}", task_number));
response.sendRedirect("wm_task.do?sys_id=" + clone);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2020 03:19 AM
Yes, Ankur it is returning the new record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2020 03:29 AM
Hi Kevin,
so it is giving the glide record object
please update as below to get the sys_id for redirection to work:
if ('false' == cancelled) {
gs.log('Inside sysid is: ' + task_id);
var gr = new GlideRecord('wm_task');
gr.get(task_id);
var clone = new SMTask().cloneTask(gr);
gs.log('Clone sysid is: ' + clone.sys_id);
(new StateFlow().processFlow(gr, '41dfa2e0d7630100fceaa6859e61035d', 'manual'));
gs.addInfoMessage(gs.getMessage("Cloned from {0}", task_number));
response.sendRedirect("wm_task.do?sys_id=" + clone.sys_id);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2020 03:38 AM
Thank you so much Ankur for your help.
Really Appreciate it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2020 03:52 AM
You are welcome..
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2020 12:11 PM
There is no default current object associated with a ui page, you need to pass in the sysid as a url parameter and then use gliderecord to look it up and update it in the processing script or client script (via ajax).
How are you accessing the record you wish to update? GlideRecord Class should be able to do this, so perhaps you have a script error in the way you're calling GlideRecord. Here is an example (note that the GlideRecord Class is called inside the evaluate tags and can be used in other evaluate sections once defined/retrieved).
<g2:evaluate jelly="true">
// Get sys_id from URL parameter
var incSysid = RP.getParameterValue("sysparm_sys_id");
// Get GlideRecord
var current = new GlideRecord('incident');
if(current.get(incSysid)){
// do something with the record here
}
</g2:evaluate>
<p>Incident State Before Update: $[current.state.getDisplayValue()]</p>
<g2:evaluate jelly="true">
// Update State to Closed
current.state = 7;
//current.update();
</g2:evaluate>
<p>Incident State After Update: $[current.state.getDisplayValue()]</p>