Need help update Asset field ( assigned to) with current Requester

Asep
Tera Contributor

Hi all, 

Thanks in advance

im looking to update Asset field (Assigned to) with current requester from Service Portal,
so far i only use one variable (asset_for_me) and of course Assigned to is depending on current state need change it first automaticaly

find_real_file.png

1 ACCEPTED SOLUTION

@Asep 

update as this

var assetGuid = current.variables.asset_for_me;
var almAsset = new GlideRecord("alm_asset");
if (almAsset.get(assetGuid)) {
    almAsset.install_status = "1";

    if(current.variables.requested_for)
        almAsset.setValue('assigned_to', current.variables.requested_for);
    else
        almAsset.setValue('assigned_to', current.request.requested_for);


    almAsset.update();
}

Regards
Ankur

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

View solution in original post

11 REPLIES 11

Murthy Ch
Giga Sage

Hi @Asep 

Asset for me is referring to which table? If it is referring to alm_asset then update the 5th line like below:

almAsset.install_status="1";
almAsset.assigned_to=current.request.requested_for.toString(); //taking the user from ritm field...

 

Thanks,

Murthy

 

 

Thanks,
Murthy

Asep
Tera Contributor

Hi Murty, 

yes, asset for me is referring to alm_asset and I've tried but not succeed yet, can you please re-check on my screenshoot and also i can't find mapping to field did i miss something?

@Asep 

Try this:

var assetGuid = current.variables.asset_for_me.toString();
var almAsset = new GlideRecord("alm_asset");
if (almAsset.get(assetGuid)) {
    almAsset.install_status = "1";
    //almAsset.assigned_to = current.variables.requested_for.toString();
    almAsset.setValue('assigned_to', current.request.requested_for);
almAsset.setWorkflow(false);
    almAsset.update();
}

Thanks,

Murthy

Thanks,
Murthy

Ankita19
Tera Guru
Tera Guru

Also try it:

current.variable.<variable>.getDisplayValue();