Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Populate Catalog task description based on Variable choices

Cat
Mega Guru

Hi All,

 

I'm hoping someone can help me with this.

 

I have a requirement to be able to populate the description of the request item/catalog task based on what was chosen in a variable.

For example, I have a variable called Team which has 10 different options. If Team 1 is selected, I need the description to say something like "Please assign the following roles: Role1, Role2, Role3". If Team 2 is selected, I need the description to say "Please assign the following roles: Role3, Role4, Role5" and so on.

 

What would be the best way for me to do this?

 

Thanks in advance!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Cat 

you can use Advanced Script in Catalog Task Activity of workflow and set the Description of SC Task

AnkurBawiskar_0-1761307924872.png

 

var val = current.variables.variableName; // give variable name here

// use the correct choice values to compare
if (val == 'Team1')
    task.description = 'Please assign the following roles: Role1, Role2, Role3';
else if (val == 'Team2')
    task.description = 'Please assign the following roles: Role3, Role4, Role5';
	// and so on

💡 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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Thank you - this worked best for my purposes

Sarthak Kashyap
Mega Sage

Hi @Cat ,

 

Please check below script maybe it will help you 

 

(function execute(current, previous) {

    var team = current.variables.team;  // Replace 'team' with your variable name

    if (!team) {
        return;
    }
    if (team == 'team1') {
        current.description = "Please assign the following roles: Role1, Role2, Role3";
        current.update();
    }
    else if (team == 'team2') {
        current.description = "Please assign the following roles: Role3, Role4, Role5";
        current.update();
    }
    else {
        current.description = "Team selection captured. Please review assignment needs.";
        current.update();
    }
})(current, previous);

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

Thank you - Where would I apply this script? Is it in the workflow? Before or after the task is created?