How to run "Populate primary resource attributes" from background script

DhathriC
Giga Contributor

I have to create a Action in flow designer, where I will be passing user sys_id. I want to trigger "Populate primary resource attributes".

12 REPLIES 12

DhathriC
Giga Contributor

@Tejas Adhalrao , I'm aware of how to create actions. I want to understand what is getting triggered or updated specifically for " "Populate primary resource attributes" UI action.

Itallo Brandão
Tera Guru

Hi Dhathri,

If you are referring to the standard Resource Management function to sync a user's roles and group memberships to the Resource tables (so they appear correctly in the Resource Finder), the Script Include you are looking for is likely ResourceAssociationManager.

Here is how you can use it in your Flow Designer Action (Script Step):

(function execute(inputs, outputs) {
    
    var userID = inputs.user_sys_id; // Map this from your Action Input
    
    if (userID) {
        // This standard library updates the resource associations (groups, roles) for the user
        new ResourceAssociationManager().updateUserAssociations(userID);
    }

})(inputs, outputs);


How to verify if this is the correct script:
If "Populate primary resource attributes" is a specific UI Action (Button) you see on a form:

  1. Right-click the button header or go to System Definition > UI Actions.

  2. Search for the name "Populate primary resource attributes".

  3. Open the record and look at the Script field. It will show you the exact API call used.

However, typically for Resource Management syncing, ResourceAssociationManager is the key class.

If this response helps you solve the issue, please mark it as Accepted Solution.
This helps the community grow and assists others in finding valid answers faster.

Best regards,

Brandão.

I have below script to run.
 
(function execute(inputs, outputs) {
// ... code ...

var grUser = new GlideRecord('sn_employee_profile');
grUser.addQuery('user',inputs.user);
grUser.query();
while(grUser.next()){

    const plngAttrsGr = new sn_plng_att_core.PlanningAttributes();
        const activeAttrs = plngAttrsGr.getAllResourceAttributes();
        attributesConfig = {}
        while(activeAttrs.next()){
            const fieldName = activeAttrs.getValue(grUser.sys_id);
            if(['primary_resource_group', 'primary_resource_role', 'primary_resource_skill'].includes(fieldName)){
                attributesConfig[fieldName] = {
                    userRefField : activeAttrs.getValue('resource_reference_field'),
                };
            }
        }
        new ResourceProfileSyncService(attributesConfig).populatePrimaryAttrsForResource(this.getParameter('resource_profile_sys_id'));
}
})(inputs, outputs);