Workflow runscript not working for GlideRecord

Aruna Sree Yela
Tera Guru

Hi,

 

Workflow run script working if I pass record number directly in the GlideRecord, and If I glide with addQuery its not working at all. Tested by adding workflow logs.

 

Passing record number directly:

workflow.info('Hi');
var jsonObj = {}; 
var res = {}; 
var parsedData = {}; 
workflow.info('script start');
var caseR = new GlideRecord('x_imports_revision_case');
caseR.addEncodedQuery("case=​POREV0001051");
caseR.query();
workflow.info('after query ' + current.case + ' & ' + current.sys_id + ' & ' + caseR.getValue("number")  + ' & ' + caseR.getValue("short_description")  + ' & ' + caseR.addQuery('case',current.case));
if (caseR.next()) {
	workflow.info('in if');
    jsonObj = caseR.json_output.toString();
    parsedData = JSON.parse(jsonObj);
    workflow.scratchpad.supplier_ship_date = parsedData.u_supplier_ship_date[0].changed_value;
	workflow.info(' the scratchpad is '+ new global.JSON().encode(workflow.scratchpad.supplier_ship_date));
    workflow.scratchpad.po_cancel = parsedData.u_po_cancel[0].changed_value;
	workflow.info(' the scratchpad is '+ new global.JSON().encode(workflow.scratchpad.po_cancel));
}

 

Output:

ArunaSreeYela_0-1708595550501.png

 

Gliding with addQuery:

workflow.info('Hi');
var jsonObj = {}; 
var res = {}; 
var parsedData = {}; 
workflow.info('script start');
var caseR = new GlideRecord('x_imports_revision_case');
caseR.addQuery('case',current.case);
caseR.query();
workflow.info('after query ' + current.case + ' & ' + current.sys_id + ' & ' + caseR.getValue("number")  + ' & ' + caseR.getValue("short_description")  + ' & ' + caseR.addQuery('case',current.case));
if (caseR.next()) {
	workflow.info('in if');
    jsonObj = caseR.json_output.toString();
    parsedData = JSON.parse(jsonObj);
    workflow.scratchpad.supplier_ship_date = parsedData.u_supplier_ship_date[0].changed_value;
	workflow.info(' the scratchpad is '+ new global.JSON().encode(workflow.scratchpad.supplier_ship_date));
    workflow.scratchpad.po_cancel = parsedData.u_po_cancel[0].changed_value;
	workflow.info(' the scratchpad is '+ new global.JSON().encode(workflow.scratchpad.po_cancel));
}

 

Output:

ArunaSreeYela_1-1708595738856.png

 

 

Thanks in Advance:)

4 REPLIES 4

_Gaurav
Kilo Sage

Hi @Aruna Sree Yela 
Can you try the below code?
Also may I know what type of field is case field?

workflow.info('Hi');
var jsonObj = {}; 
var res = {}; 
var parsedData = {}; 
workflow.info('script start');
var caseR = new GlideRecord('x_imports_revision_case');
caseR.addEncodedQuery('case='+current.case);
caseR.query();
workflow.info('after query ' + current.case + ' & ' + current.sys_id + ' & ' + caseR.getValue("number")  + ' & ' + caseR.getValue("short_description")  + ' & ' + caseR.addQuery('case',current.case));
if (caseR.next()) {
	workflow.info('in if');
    jsonObj = caseR.json_output.toString();
    parsedData = JSON.parse(jsonObj);
    workflow.scratchpad.supplier_ship_date = parsedData.u_supplier_ship_date[0].changed_value;
	workflow.info(' the scratchpad is '+ new global.JSON().encode(workflow.scratchpad.supplier_ship_date));
    workflow.scratchpad.po_cancel = parsedData.u_po_cancel[0].changed_value;
	workflow.info(' the scratchpad is '+ new global.JSON().encode(workflow.scratchpad.po_cancel));
}

 

@_Gaurav Case type is "Composite Field".

 

I tried the above code, but no luck for Case field and Number[string] field as well.

 

Thanks

piyushsain
Tera Guru
Tera Guru

@Aruna Sree Yela 

Can you please try current.case.toString()

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

@piyushsain Not working!

 

And I can be sure that current.case was fetching the value correctly. If you see the below log

 

workflow.info('after query ' + current.case + ' & ' + current.sys_id + ' & ' + caseR.getValue("number")  + ' & ' + caseR.getValue("short_description")  + ' & ' + caseR.addQuery('case',current.case));

 

ArunaSreeYela_0-1708606427186.png

 

Thanks