Need to display the value in single line text field from list collector field

suuriya
Tera Contributor

Hi,

 

I have a requirement, in catalog form we have list collector field (will be displayed only on portal not in ritm and task) and in ritm and task we have single line text field (will not display in portal) while raising the request values selected in the list collector need to be populate in the single line text (ritm and task) ...how can we achieve it

 

Please help me with the full script 

Thanks in Advance

1 ACCEPTED SOLUTION

Hello,

 

Please use the below script:-

 

(function executeRule(current, previous /*null when async*/) {

current.variable.singlelinetextvariablename=current.variables.listcollectorvaribalename.getDisplayValue();

})(current, previous);

 

Please mark my answer as correct based on Impact.

View solution in original post

4 REPLIES 4

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Is the single line text a variable or a field? 

 

If it is a field write the below code in the before insert BR:-

 

Condition:- Item is (select the item name)

 

(function executeRule(current, previous /*null when async*/) {

current.singlelinetextfieldname=current.variables.listcollectorvaribalename;

})(current, previous);

 

If it is a variable write the below code in the before insert BR:-

 

(function executeRule(current, previous /*null when async*/) {

current.variable.singlelinetextvariablename=current.variables.listcollectorvaribalename;

})(current, previous);

 

Please mark my answer as correct based on Impact.

suuriya
Tera Contributor

Hi Saurav,

 

It is a variable and i tried the BR but it is displaying its sys id not the name

How can we modify the script so that the value will be shown 

suuriya_0-1670241158556.png

 

Hello,

 

Please use the below script:-

 

(function executeRule(current, previous /*null when async*/) {

current.variable.singlelinetextvariablename=current.variables.listcollectorvaribalename.getDisplayValue();

})(current, previous);

 

Please mark my answer as correct based on Impact.

jaheerhattiwale
Mega Sage
Mega Sage

@suuriya Please try below code

 

var requiredNames = [];

var targetTable = new GlideRecord("<TABLE REFERNCING THE LIST COLLECTOR>");
targetTable.addQuery("sys_idIN"+current.variables.<LIST COOLLECTOR FIELD NAME HERE>);
targetTable.query();

while(targetTable.next()){
    requiredNames.push(targetTable.getValue("<REQUIRED TARGET TABLE NAME HERE>"));
}

current.variables.<SINGLE LINE TEXT FIELD NAME HERE> = requiredNames;
current.update();
 
Please mark as correct answer if this solves your issue.
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023