How to autopopulate field in request table based on input given before submitting the request

Priyanka77
Tera Guru

Hi,

 

I need to autopopulate custom field in request table based on input given in variable before submitting the request through catalog item. I have created as a variable set because i will be using that variable in multiple catalog items and created that custom field in request table as well.

 

Can someone please suggest me on this.

 

Thanks in advance!

Priyanka 

 

 

4 REPLIES 4

Community Alums
Not applicable

Hello @Priyanka77 ,

 

For this, you can write a function like this:

 

function calculateScript() {
var variablesResponses = [];
var val = current.variables.getElements();
for (var i = 0; i < val.length; i++) {
var j = {};
var variableObject = val[i].getQuestion();
j.question = variableObject.getLabel();
j.response = variableObject.getDisplayValue();
variablesResponses.push(j);
}
return variablesResponses;
}

 

"variablesResponses" will return a JSON array of catalog variables; you can call this function for your custom field as per your requirement.

 

@Priyanka77 , Please mark my answer as "Accept as Solution" and "Helpfuls." If it works for you.

 

Thank You!

 

 

Thanks for your response @Community Alums 

But where I need to write this function and if its business rule then table will be sc_request?

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Priyanka77 

how would you know which REQ is there even before submitting the request?

are you using flow designer or workflow for your catalog item?

it would be nice if you share screenshots of the custom field and other things.

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

Thanks for your response @Ankur Bawiskar 
I am using that variable in request table as well and I am mapping that after submission of request. I have achieved the functionality via business rule. Thank you