Trigger Client Script to run on all Asset records

AndyB5000
Mega Guru

OOB SNOW has a client script on the alm_asset table, "Set Loc/CC/Dep/Com from assigned to", that fills in the field when the assigned to attribute is filled in.  

 

My question is can we force this Client Script to run on all Asset records even if the assigned to is already filled in.  We have found many records have the correct assigned to user but their business unit or company did not update properly when their named was added through the list view.

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @AndyB5000 ,

 

 

To maintain the existing setup of the OOB client script triggered on the onChange event of the Assigned_to field, it's advisable not to make significant modifications.

However, creating an onLoad client script can ensure the values of Loc/CC/Dep/Com are set from Assigned_to when the field is not empty. This script will consistently update the correct values whenever a user opens and saves the form.

Additionally, the 'Set Loc/CC/Dep/Com from assigned to' client script fills in the fields when the 'Assigned_to' attribute is updated in onChange. This script ensures data correctness.

You can reference the script below, composed using the logic from 'Set Loc/CC/Dep/Com from assigned to':

function onLoad() {
        if (g_form.getValue('install_status') == 2 || g_form.getValue('install_status') == 6 ||
                g_form.getValue('install_status') == 9)
                return;

        g_form.getReference('assigned_to', setLocation);

}

function setLocation(assignee) {
        if (assignee && assignee.location != '')
                g_form.setValue('location', assignee.location);
        g_form.setValue('cost_center', assignee.cost_center);
        g_form.setValue('department', assignee.department);
        g_form.setValue('company', assignee.company);
}

If your requirement differs, you can establish the setting of Loc/CC/Dep/Com from the 'assigned to' field by employing a fixed script, scheduled job, or possibly a business rule for all the records in the alm_assets table. Let me know if required I will assist you on that.

 

Please mark it as helpful and accept it as a solution if it assists you in any way.

 

Thank you!

Prasad

View solution in original post

1 REPLY 1

Community Alums
Not applicable

Hi @AndyB5000 ,

 

 

To maintain the existing setup of the OOB client script triggered on the onChange event of the Assigned_to field, it's advisable not to make significant modifications.

However, creating an onLoad client script can ensure the values of Loc/CC/Dep/Com are set from Assigned_to when the field is not empty. This script will consistently update the correct values whenever a user opens and saves the form.

Additionally, the 'Set Loc/CC/Dep/Com from assigned to' client script fills in the fields when the 'Assigned_to' attribute is updated in onChange. This script ensures data correctness.

You can reference the script below, composed using the logic from 'Set Loc/CC/Dep/Com from assigned to':

function onLoad() {
        if (g_form.getValue('install_status') == 2 || g_form.getValue('install_status') == 6 ||
                g_form.getValue('install_status') == 9)
                return;

        g_form.getReference('assigned_to', setLocation);

}

function setLocation(assignee) {
        if (assignee && assignee.location != '')
                g_form.setValue('location', assignee.location);
        g_form.setValue('cost_center', assignee.cost_center);
        g_form.setValue('department', assignee.department);
        g_form.setValue('company', assignee.company);
}

If your requirement differs, you can establish the setting of Loc/CC/Dep/Com from the 'assigned to' field by employing a fixed script, scheduled job, or possibly a business rule for all the records in the alm_assets table. Let me know if required I will assist you on that.

 

Please mark it as helpful and accept it as a solution if it assists you in any way.

 

Thank you!

Prasad