How to pass the current object in ui page(html) to processing script ?

Kevin Smith2
Giga Expert

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

1 ACCEPTED SOLUTION

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

24 REPLIES 24

In my ui action I am using 'sysId'. i.e. jvar_taskid.

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

I got it working using this code:

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);
    (new StateFlow().processFlow(gr, '41dfa2e0d7630100fceaa6859e61035d', 'manual'));
    gs.addInfoMessage(gs.getMessage("Cloned from {0}", task_number));
    response.sendRedirect("wm_task.do?sys_id=" + clone);
}

However, it is not redirecting it.

It is returning:  [object GlideRecord]

How can I rectify this ?

 

Hi Kevin,

I just added the same comment that you already had a hidden element to store the sys_id

Glad that it worked.

To which record you need to redirect?

the variable clone is holding what value?

Is it holding sys_id of the new wm_task record?

what is this log giving you?

	gs.log('Clone sysid is: ' + clone);

Regards
Ankur

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

It is should redirect to the cloned record as it is doing successfully in normal ui action using(action.setRedirectURL(clone);).

But here I am getting this:

Clone sysid is: [object GlideRecord]