Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Regarind MRVS value read and set it into a multiline text

1_DipikaD
Kilo Sage

 Hi all, I have a requirement of get the MRVS values and set it into a Multiline text which is present inside a SingleRow Variable set from a catalog item but when it came to RITM and sc_task the vlaue is not visible accurately as expected.

i have attached the picture i have to set memebr of the distribution list  to the ITS CE-API API variable which is a multiline text set inside a single row variable set. i have write a OnSubmit() client script.but it is not giving accurate output it is show '/'  and the sys-id of the member i have tried

function onSubmit() {
    // Retrieve the value of the 'members_of_the_distribution_list' field
    var mvrsValue = g_form.getValue("members_of_the_distribution_list");
   
    g_form.setValue("api_variable", JSON.stringify(mvrsValue));
  
}

but it is not working can any one suggest how to achieve it through workflow

1__AshishKumaD_0-1715324775877.png

@Ankur Bawiskar 

5 REPLIES 5

dgarad
Giga Sage

Hi @1_DipikaD 

 '/' is shown because you use JSON.stringify method. use JSON.parse.

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

i have applied JSON.parse but still i got like this member variable is returning sysid of user which is refer to user table but want to get the actual value. member variable is a reference field present inside the MRVS.

1__AshishKumaD_0-1715346342417.png

 

 

try the below code and modify it as per requirement.

var mrvs = JSON.parse(g_form.getValue("members_of_the_distribution_list"););//array of objects with values
var returnStr= '';//return string
for(var i=0; i < mrvs.length; i++); {
  if(mrvs[i].memeber !=""){
    var gr = new GlideRecord('sys_user');
    if(gr.get(mrvs[i].member)){//I assume u_user_name is a ref. to sys_user
      returnStr += "member: " + '\n' + gr.getValue('user_name') + '\n';
      returnStr += "Email: " + mrvs[i].email + '\n' 
      returnStr += "User_id: " + mrvs[i].user_id + '\n' ;
      
  }
}
  g_form.setValue("api_variable", returnStr);
If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

I have just modify the code and tried it using workflow runscript but still the value not populate, i have applied gs.info() that is produce proper result but the result is not set in the multiline text field .i have written this code below

 
 
var mvrs = JSON.parse(current.variables.members_of_the_distribution_list);
 current.requested_for = usr;
current.business_service = bs;
var mrvsValue = mvrs;
    var returnStr = ''; //return string
    for (var i = 0; i < mrvsValue.length; i++) {
        var memberName=mrvsValue[i].member;
 var gr = new GlideRecord('sys_user');
        gr.addQuery('sys_id', memberName);
        gr.query();
        if (gr.next()) {
            var newName=gr.name;
            returnStr += "member: " + newName + "Email: " + mrvsValue[i].email + "userId" + mrvsValue[i].user_id + '\n';
        }
    }
        gs.info(">>>>>>>>>"+returnStr);
        current.api_variable=returnStr;
the gs.info () provide actual result but the next line is not set the value.
it is a multiline text present inside a single row variable set. and it is hide in RITM  and catalog item only visible in Catalog task.