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

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();
})

 

@Brad Bowman  , @Ankur Bawiskar I implemented the script as shown, but it’s still not working. Did I miss anything?

} else if (department == "41b89a9edb5d0850386debd848961930") { // Training
    arr = [{
        "short_description": "Offboarding | Remove access from Docusign",
        "description": "1. Docusign",
        "assignment_group": "e276e46cdb414410386debd8489619d1",
        "template": "8d7b6ef41b314c10611c11b92a4bcb00" //Docusign
    }];

} else { 
    arr = [];
}

var taskIds = [];

arr.forEach(function(elem) {
    var grScTask = new GlideRecord('sc_task');
    grScTask.initialize();
    grScTask.setValue('short_description', elem.short_description);
    grScTask.setValue('description', elem.description);
    grScTask.setValue('assignment_group', elem.assignment_group);
    grScTask.setValue('parent', workflow.scratchpad.taskid1);
    grScTask.setValue('request_item', current.sys_id);
    var recordSysID = grScTask.insert();

	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();
	});

    taskIds.push(recordSysID);
    
    var newTaskId = recordSysID;
   
    var checklistArr = {};
    var templateSysId = '';

    templateSysId = elem.template;
    
    var JS_N = new GlideRecord('checklist_template');
    JS_N.get(templateSysId);
    checklistArr = JSON.parse(JS_N.getValue('template'));

    var chk = new GlideRecord('checklist');
    chk.initialize();
    chk.document = newTaskId;
    chk.table = 'sc_task';
    
    var checklistId = chk.insert();

});

 

@Vijay Kumar4 

did you check if record got inserted into that table? sc_item_variables_task

also does your catalog task form has Variable Editor added on form layout?

55.png

💡 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

@Brad Bowman  Thanks, its working.