Calling a Script Include from UI action

Rutusha
Tera Contributor

HI All,

I have a requirement where I need to show the UI action if the logged in user is part of some group and current state of the record is new or assessment. And if the user is not part of that group, then that UI action should only be visible in new state and no other state.

To achieve this, I have written a script include and later called that script include in UI action.

But somehow it is not working.

Could someone help me here to check where I'm going wrong. 

 

Script Include Code(client callable is not checked)

UiActionVisibilityfunction(currObj){
        //var memberOfGroup = gs.getUser().isMemberOf('TPX-Connect-ChangeManagement-CORE');
        if((gs.getUser().isMemberOf('TPX-Connect-ChangeManagement-CORE')) && ((currObj.state==-4 || currObj.state==29 || currObj.state==-3 || currObj.state==-2 || currObj.state==-1))){
            gs.info('1st loop');
            return true;
        }else if(currObj.state==-5 ){
gs.info('2nd loop');
            return true;
        }return false;

    },
 
UI action condition where the above script include is called
new global.CINotFoundUIActionVisibility().UiActionVisibility(current);
4 REPLIES 4

Jaspal Singh
Mega Patron
Mega Patron

Hi Rutusha,

 

Try below.

UiActionVisibility: function(currObj){
        //var memberOfGroup = gs.getUser().isMemberOf('TPX-Connect-ChangeManagement-CORE');
        if((gs.getUser().isMemberOf('TPX-Connect-ChangeManagement-CORE')) && ((current.state==-4 || current.state==29 || current.state==-3 || current.state==-2 || current.state==-1))){
            gs.info('1st loop');
            return true;
        }else if(current.state==-5 ){
gs.info('2nd loop');
            return true;
        }return false;

    },

 new global.CINotFoundUIActionVisibility().UiActionVisibility();

 

Also, try replacing name of group with sys_id of group.

Community Alums
Not applicable

Hi @Rutusha ,

You can try below code

In Ui action you have to add this code which client callable

 

var ga = new GlideAjax('ScriptIncldueName');
      ga.addParam('sysparm_name', 'FunctionName');
      ga.addParam('sysparm_buildingid', "Parameter_value");
      ga.getXML(updateCampus);

function updateCampus(response) {
      var answer = response.responseXML.documentElement.getAttribute("answer");
      alert(answer);
}

 

Script Include (which is client callable)

 

asu_GetLocationData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
      functionName: function () {
              var buildingid = this.getParameter('parameter_value');
              Your logic
      }
});

 

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

Maddysunil
Kilo Sage

@Rutusha 

  1. Check Script Include Invocation: Make sure that the script include CINotFoundUIActionVisibility is properly instantiated and invoked in your UI action script. Ensure that there are no syntax errors or typos in the script include name or method invocation.

  2. Verify Group Membership Check: Double-check that the group name 'TPX-Connect-ChangeManagement-CORE' is correct and that the logged-in user is indeed a member of this group. You can verify this by logging the output of gs.getUser().isMemberOf('TPX-Connect-ChangeManagement-CORE') to ensure it returns the expected value.

  3. Check Current Object Properties: Ensure that the current object passed to the script include method contains the state property and that it represents the correct state of the record. You can log current.state to verify its value during execution.

  

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Community Alums
Not applicable

Do you see this UIAction at all? If not maybe its the condition, I'd use something like:

if(new global.CINotFoundUIActionVisibility().UiActionVisibility(current))

 

P.S. What type is your UIAction ?