Not able to update catalog task state using custon ui action by end user

Sharath807
Tera Contributor

I created a custom ui action in sc_task form with some logics,  including updating the state field to closed complete on clicking it. But it works as expected if the user has admin role. But when agents( who has no admin role) clicks other logics are working but state is not getting closed completed in sc task form. Any help?

15 REPLIES 15

@Sharath807 

is that user manually change from form?

Is that user able to click Close Complete on SC Task and what happens?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar The user can change state manually, but my requiremnt is to update when the custom button is clicked . Also if the same user clicks  OOB 'Close Task' ui action button the task is getting closed .
But as admin if i click the custom ui action, The state is updating 


@Sharath807 

why are you using glideRecord to update?

why not use current object?

 var grAsset = new GlideRecord('alm_asset');
 if (grAsset.get(current.u_asset + '')) {
     gs.log("@@@@@@@@@@@@@");
     if (current.request_item.cat_item == 'xxx') { // request for a computer
         // if (current.request_item.cat_item == 'xxx') {
         //alert('in');
         gs.log("66666");
         var date_time = gs.nowDateTime();
         grAsset.assigned_to = current.request.requested_for;
         grAsset.owned_by = ownedBy; /*To put condition once confirmed*/
         grAsset.install_status = 1;
         grAsset.substatus = '';
         grAsset.assigned = date_time;
         grAsset.asset_function = current.request_item.variables.asset_type;
         grAsset.work_notes = "Asset has been allocated to user as per " + current.request_item.number;

         grAsset.update();

         current.state = 3;
         current.work_notes = "Asset allocated and task closed";
         current.update();
     } else {
         gs.log("Failed to update task: Record not found");
     }
     gs.addInfoMessage('Asset <b>' + current.u_asset.display_name + '</b> allocated successfully to <b>' + current.request.requested_for.name + '</b>');

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Anubhav24
Mega Sage
Mega Sage

Hi @Sharath807 ,

The issue might be with alm_asset table the non admin user might no be having access to this table, can you check if this user have the permissions to update this record using access analyzer ?

Sharath807
Tera Contributor

@Ankur Bawiskar  while using current object...Getiting errors like.
1.Invalid update
2.Failed to close the task. Please allocate the selected asset by clicking the "Assign Asset" button.
3.gs.addInfoMessage('Asset <b>' + current.u_asset.display_name + '</b> allocated successfully to <b>' + current.request.requested_for.name + '</b>');