JSON Object Empty String

Kiran Patil3
Giga Expert

HI

I am trying to build JSON object to use in one of the integration. Below code works fine if used hardcoded value but fail if use workflow scratchpad variables. I am trying to execute this in service catalog workflow activity. anyone face same issue?

workflow.scratchpad.account_id = current.variables.account_id;  //Works if hardcode value here
workflow.scratchpad.change_request = current.variables.change_request; ////Works if hardcode value here
workflow.scratchpad.number = getTaskNumber(current.sys_id);

var requestBody = {};


	function getTaskNumber(requestItem){

		var getTask = new GlideRecord('sc_task');
		getTask.addQuery('requested_item',requestItem);
		getTask.addQuery('active', true);
		getTask.query();
		while(getTask.next())
			{
			//gs.addInfoMessage("Task: " + getTask.number + " Staus: " + getTask.state);
                     var ticket_number = getTask.number;
				return ticket_number;			
			}			
		}


requestBody.account_id = current.variables.account_id;
requestBody.change_request = workflow.scratchpad.number;
requestBody1 = new global.JSON().encode(requestBody);

workflow.info("JSON Body: " + requestBody1+ "\n " + "Function Return: " + workflow.scratchpad.number);

 

 

Output:

JSON Body: {"account_id":{},"change_request":{}}
 Function Return: SCTASK0010044

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

Can you change below two lines to

 

requestBody.account_id = current.variables.account_id+'';
requestBody.change_request = workflow.scratchpad.number+'';

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

4 REPLIES 4

SanjivMeher
Kilo Patron
Kilo Patron

Can you change below two lines to

 

requestBody.account_id = current.variables.account_id+'';
requestBody.change_request = workflow.scratchpad.number+'';

Please mark this response as correct or helpful if it assisted you with your question.

Please mark the response correct if it worked for you


Please mark this response as correct or helpful if it assisted you with your question.

Kiran Patil3
Giga Expert

Hi Sanjiv

Thanks for reply. It worked.

Raja Mohsin1
Tera Contributor

HI Sanjiv

This is strange behavior, it worked but can you please explain that why it happened.


Thanks,