Variable editor not visible in some SCTASKS

Vijay Kumar4
Giga Guru

I have added a variable editor to the Catalog Task (SCTASK) layout. I have a catalog item: Onboarding. When this catalog item is submitted, its related SCTASK record is created through a workflow.

In the workflow, some catalog tasks are created using the Catalog Task activity, while others are created using scripts.

For the SCTASK records created using the Catalog Task activity, I am able to see the Variable Editor. However, for the tasks created using scripts, the variable editor is not displayed.

Could someone help me understand why the variable editor is not appearing for tasks created via scripts?

Please refer to the workflow screenshot below. Also, here is a snippet from the script used to create the task for reference:

 
 
 

sc.png

 

scr.png

 

 

SCTASK created using catalog task element

variable.png

SCTASK created using script:
non-ve.png



1 ACCEPTED SOLUTION

Brad Bowman
Mega Patron

The Variable Editor formatter is part of the sc_task form out of box, so I'm confused that you 'added' one.  In any event, the variables aren't visible on your scripted task because you didn't add any variables in the script!  You can use something like this within your for each loop after each task is created:

var ritmVariables = current.variables.getElements();
ritmVariables.forEach(function(ritmVar) {
    grTaskVar = new GlideRecord('sc_item_variables_task');
    grTaskVar.newRecord();
    grTaskVar.task = newTaskId;
    grTaskVar.variable = ritmVar.getQuestion().id;
    grTaskVar.insert();
})

 

View solution in original post

6 REPLIES 6

@Vijay Kumar4 

what was the issue and what you did to resolve that?

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

Ankur Bawiskar
Tera Patron

@Vijay Kumar4 

those created from script won't get the variable editor by default

you need to create record into table "sc_item_variables_task"

Script already shared by @Brad Bowman  

also check this link

Adding Variables to a Task via a script instead of using the slush bucket within a workflow for a Ca... 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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