Populate Requested for variable user mail address in Task des

Manohararuna
Tera Contributor

Hello Everyone,

 

    I have one requirement.

Requested for field is list collector type in Catalog item .if select multiple users then selected users related mail address are should populate in Task des under RITM.

For this i want script in Task event in Workflow.

How can i fix this problem

Manohararuna_0-1755852208491.png

 

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@Manohararuna 

so email addresses of those users should be populated where?

Example: I am taking description field for my reference, you can use this advanced script in Create Catalog Task Activity

var myArray = current.variables.listCollectoVariableName.toString().split(','); // give your variable name here

var emailArray = [];

for (var i = 0; i < myArray.length; i++) {
    //myArray[i];
    var gr = new GlideRecord("sys_user");
    gr.addQuery("sys_id", myArray[i]);
    gr.query();
    if (gr.next()) {
        emailArray.push(gr.getValue('email'));
    }
}

task.description = 'Email addresses are ' + emailArray.toString();

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

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

View solution in original post

@Manohararuna 

I believe I took example of description field and you can enhance the logic further now.

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

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

View solution in original post

10 REPLIES 10

Bhuvan
Kilo Patron

@Manohararuna 

 

If you are creating a new workflow for this, recommend you to use Flow Designer and create a Flow as it is the recommended solution from ServiceNow and is much easier to configure and manage it.

 

You can use below thread to capture requested_for information via list collector from RITM and populate their email addresses in Task,

 

https://www.servicenow.com/community/developer-forum/list-collector-email-address/m-p/1377613

 

If this helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan

Thanks for the reply but i want script help in Task event.

Ankur Bawiskar
Tera Patron
Tera Patron

@Manohararuna 

so email addresses of those users should be populated where?

Example: I am taking description field for my reference, you can use this advanced script in Create Catalog Task Activity

var myArray = current.variables.listCollectoVariableName.toString().split(','); // give your variable name here

var emailArray = [];

for (var i = 0; i < myArray.length; i++) {
    //myArray[i];
    var gr = new GlideRecord("sys_user");
    gr.addQuery("sys_id", myArray[i]);
    gr.query();
    if (gr.next()) {
        emailArray.push(gr.getValue('email'));
    }
}

task.description = 'Email addresses are ' + emailArray.toString();

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

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

Hello Ankur, Thanks for your reply.i want to populate those users email address in Task desc fields(Task created under RITM part of Catalog item).Please see the below images for your referecne

Manohararuna_0-1755853193325.png

Manohararuna_1-1755853223962.png