Cloned sctask not populating all the variables

Jyo7
Tera Contributor

Hello , 

Iam facing a scenario wherein Cloned sctask not populating all the variables , Instead it is populating only few , when deep diven , I found out that its populating the variables which are marked as Global = True , Please suggest any solutions for this , 

Instead , should I write this in a UI Action script to populate all the variables independent of Global marking , 
Appreciate any responses.Thanks

 

2 ACCEPTED SOLUTIONS

Nikhil Bajaj9
Tera Sage

Ajay_Chavan
Kilo Sage

 

Setting variables to Global=true makes them available on requested items as well as catalog task forms. The Global field controls variable visibility across RITM and catalog tasks.

 

Answer to your question: The issue you're experiencing is expected OOB behavior. 

 

Global Field Purpose:

  • Variables set to Global=true are available on both RITM and catalog task forms
  • Global=false variables are typically limited to the original context
  • During cloning operations, only Global=true variables copy over

Solutions remain the same:

Option 1: Set Required Variables to Global=True Add 'Global' field to your catalog item variables list view and set relevant variables to Global=true

Option 2: UI Action with Custom Script

// Copy all variables regardless of Global setting
var variables = new GlideRecord('sc_item_option_mtom');
variables.addQuery('request_item', sourceRITM);
variables.query();
while(variables.next()) {
    // Create variable associations for new task
}

Recommendation: The Global=true approach aligns with ServiceNow's intended design, while custom scripting gives complete control over variable copying behavior.

 

 

View solution in original post

4 REPLIES 4

Nikhil Bajaj9
Tera Sage

Ankur Bawiskar
Tera Patron

@Jyo7 

how are you cloning? share that script and screenshot

If my response helped please mark it correct and close the thread so that it benefits future readers.

Hello Ankur , 

Thanks for the Reply , Im attaching the UI action code snippet for your further clarification needed.

// Clone the current catalog task - UI Action - Clone Request Center Task

var originalTask = current.getValue("number");

var clonedTask = new CatalogTask().cloneTask(current);

 

// redirect to the newly cloned task

action.setRedirectURL(clonedTask);

gs.addInfoMessage(gs.getMessage("Cloned from {0}", originalTask));

 

//Script Include CatalogTask

 

var CatalogTask = Class.create();

CatalogTask.prototype = {

    initialize : function() {

    },

   

    cloneTask : function(original) {

        var className = original.sys_class_name + '';

       

        // Clone this task to a new, mostly identical, task

        var clone = new GlideRecord(className);

       

        // The fields listed below are copied from the original task

       

        clone.request_item = original.request_item;

        clone.sys_domain = original.sys_domain; // System

        clone.assignment_group = original.assignment_group;

        clone.short_description = original.short_description;

        clone.state = 1;

       

        // Activity Log

        clone.work_notes = gs.getMessage("Cloned from catalog task {0}", original.number);

       

        // Create the new task

        clone.insert();

       

        // Return the newly cloned record

        return clone;

       

    },



Ajay_Chavan
Kilo Sage

 

Setting variables to Global=true makes them available on requested items as well as catalog task forms. The Global field controls variable visibility across RITM and catalog tasks.

 

Answer to your question: The issue you're experiencing is expected OOB behavior. 

 

Global Field Purpose:

  • Variables set to Global=true are available on both RITM and catalog task forms
  • Global=false variables are typically limited to the original context
  • During cloning operations, only Global=true variables copy over

Solutions remain the same:

Option 1: Set Required Variables to Global=True Add 'Global' field to your catalog item variables list view and set relevant variables to Global=true

Option 2: UI Action with Custom Script

// Copy all variables regardless of Global setting
var variables = new GlideRecord('sc_item_option_mtom');
variables.addQuery('request_item', sourceRITM);
variables.query();
while(variables.next()) {
    // Create variable associations for new task
}

Recommendation: The Global=true approach aligns with ServiceNow's intended design, while custom scripting gives complete control over variable copying behavior.