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.

Retrieve data from List type field and Update User Data

Vamshi_ch123
Tera Contributor

Hi All,

I'm trying to retrieve the value of the list-type field 'u_product_list' for the user with the role 'customer_admin' whose contact corresponds to the current value. After that, I want to update the product list for the newly created user in the 'customer_contact' table. However, the script provided is not functioning as intended using workflow

var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('role.name', 'sn_customerservice.customer_admin');
gr.addQuery('user.company', current.account);
gr.query();

if (gr.next()) {
var usr = new GlideRecord("customer_contact");
usr.first_name = current.first_name;
usr.last_name = current.last_name;
usr.email = current.email;
usr.phone = current.u_phone_number;
usr.preferred_language = current.u_language;
usr.u_watchlist = current.u_watchlist;
var user_name = current.u_user_id;
var user_name_available = user_name;
var dup = new sn_customerservice.CSPortalUtil().isDuplicateUserID(user_name_available);
if (!dup) {
	usr.user_name = current.u_user_id;
    usr.account = current.account;
    var productList = [];
    productList.push(gr.user.u_product_list.getValue().toString());
    gs.log(productList);
    usr.u_product_list = productList;
    var newpw = new sn_customerservice.CSPortalUtil().createPassword();
    usr.user_password.setDisplayValue(newpw);
    usr.password_needs_reset = true;
    var userid = usr.insert();
    
    }
}

 Thanks & Regards

Vamshi

1 REPLY 1

Maddysunil
Kilo Sage

@Vamshi_ch123 

What are you getting in this log:

gs.log(productList);