Getting Catalog Item variable to Workflow Scratchpad.

Wesley Breshear
Tera Expert

Hello,

I have read a few ServiceNow articles and it appears you can get/pass Request Item variables to the Workflow Scratchpad OOB.  Anyway having a problem or missing why I am not getting the value to the scratchpad. 

So, on the sc_cat_item table, I created a new column called Manager Approval (u.manager.approval) [True/False].  This way on all our current catalog items a catalog admin can select if the Catalog item requires Manager Approval.  In my workflow, I have the below IF condition to look to see if the Catalog item has the 'Manager Approval' checkbox set to True or False.  But my workflow.scratchpad.u_manager_approval the variable is undefined.  Am I missing something?

answer = ifScript();
var manApp = workflow.scratchpad.u_manager_approval;
//var manApp = current.variable_pool.u_manager_approval;

gs.info('manApp Value: ' + manApp);  // returns 'undefined'

function ifScript() {
 if (manApp == true) {
 return 'yes';
 }
 return 'no';
}

gs.info('Answer Value: ' + answer); // returns 'no'

Here is an article that I referenced: 

https://community.servicenow.com/community?id=community_question&sys_id=ddc013a9dbdcdbc01dcaf3231f9619f7 

 

Thank you,

-Wesley

 
1 ACCEPTED SOLUTION

I get it now, you can do this through filter condition, doesn't require scripting, like below, to check if manager field is true then if activity will return true else it will return false.

 

find_real_file.png

 

 

find_real_file.png

 

find_real_file.png

 

View solution in original post

16 REPLIES 16

I did both.  Ideally, I would rather use the field/column that I placed on the sc_cat_item table, this way you can just check a box to say you want manager approval for the cat item.  We have been trying to stay with on Workflow rules them "all", meaning we are using only one workflow for all our catalog items.  So passing the value into the workflow would be ideal.  But I also tried creating a variable on the catalog item (request item) as well called 'u_manager_approval' as well; Yes/No.  The disadvantage is will always need to create a UI policy to hide it and set the default value within the variable.  But still not able to pass its value to the workflow either.  Hope this makes sense. 🙂

-Wesley

Can you please share the code you are using in workflow, ideally this should work 

var manApp = current.u_manager_approval;

 

does it always returns 'no'?

 

can you have true keyword in quotes in if condition and then try, let's see if this helps.

if (manApp =='true')

 

Hoping the checkbox is checked before it reaches to if activity in workflow.

 

Wesley Breshear
Tera Expert

Okay,

Had a typo, so the Catalog variable "current.variables.u_manager_approval_2" is now passing the "Yes" value.  So that version is working; but not ideal.

But I am still getting "undefined" for the sc_cat_item field.  Also, tried your suggestion of 'true' vs. true (quotes).  No success.  Maybe, I am having an issue with passing the sc_cat_item field vs. what you said sc_req_item table.

I have added some pictures to help with what I am trying to do.

 

Thank you,

Wesley

Shishir Srivast
Mega Sage

okay, so you have u_manager_field on sc_cat_item table that's why workflow is throwing undefined, since the workflow is running on sc_req_item table not on the sc_cat_item table and sc_cat_item table does not have u_manager_field field.

 

You need to have u_manager_field on sc_req_item table then you will be able to use below code.

var manApp2 = current.u_manager_approval;

 

sc_cat_item is a table which contains all the catalog items not the actual tasks (request items) which are created on top of that. 

Hi Shishir,

Understand what you are saying, but not knowing how to make my setup work.  If the u_manager_approval field is on the sc_request_item table then I don't believe there is a way to make certain catalog items require manager approval if a check box is selected.

Not positive if there is another way, but I am assuming in the workflow IF properties box, that it would then need to do a glide record query against the sc_cat_item table pull all items that have u_manager_approval = true then validate if the current request item is equal to one of those catalog items in the query.  Any other ideas, or am I missing something in your answer?

-Wesley