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

View solution in original post

11 REPLIES 11

suvro
Mega Sage

Since you are only using one variable I  assume there is no variable for requested for. So we need to fetch that using current.request.requested_for 

So the assigned_to should be populated like below

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

Ankur Bawiskar
Tera Patron

Hi,

If you have a variable for Requested For then use that or you can use request-> requested for

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

Regards
Ankur

Hi ankur,

sorry can you please write in full script?

Hi,

Please start from your side and it will be a learning for you as well.

I already shared sample script above which can be used in workflow run script

Regards
Ankur

thanks, will be new lesson, since im also new learning on scripting thanks to all also, beside screenshoot this is what i have so far that work couple time test but using alm_hardware table but also pop up some error sometime. but still didn't work for asset (alm_asset)

var assetGuid = current.variables.asset_for_me.getDisplayValue();
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.update();
}