Implement user criteria using scripts

Takumi Togashi
Tera Expert

I am trying to control the display of catalog items on the portal screen.
I would like to display them only to users who meet the following conditions.
・The company information of the logged-in user must be A or B.
・If the logged-in user's company information is A, the specific column information (let's say C) is not empty.

3 REPLIES 3

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Takumi Togashi ,

 

Can u give this code a try.

 

(function() {

    // Get the current user's company and specific column value

    var currentUserCompany = gs.getUser().getCompanyID(); // Assuming the user's company information is stored in the 'company' field

    var specificColumnInfo = current.getValue('specific_column'); // Replace 'specific_column' with the actual field name

 

    // Check conditions: Company is A or B, and if company is A, specific column is not empty

    if ((currentUserCompany == 'A' || currentUserCompany == 'B') && (currentUserCompany != 'A' || specificColumnInfo)) {

        return true; // Return true to make the catalog item visible

    } else {

        return false; // Return false to hide the catalog item

 

  }

 

})();

 

Mark my answer helpful & accepted if it helps you resolve your query.

 

Thanks,

Danish

@Danish Bhairag2 

 

Thank you for your response.

 

I tried but it did not seem to show up for users whose company is A and the particular column is not empty, nor for users whose company is B. I am not sure if this is due to the fact that the column is not empty or not.

 

I would like to confirm one point. I am aware that A and B will have SysIDs, is this correct?


if ((currentUserCompany == 'A' || currentUserCompany == 'B') && (currentUserCompany ! = 'A' || specificColumnInfo))

Hi @Takumi Togashi ,

 

Yes it is correct.

 

Thanks,

Danish