This topic contains 3 replies, has 0 voices, and was last updated by TheUsualSuspect 6 years, 4 months ago.

  • Author
    Posts
  • #17977

    vkwanengage

    Hello NS community,

    I was wondering, is there a way to get all users who have “Administrative Role” via SuiteScript? I want to be able to get all these users so i can alert them of some actions via email.

    Thanks.
    This is a cached copy. Click here to see the original post.

  • #17978

    dominicb

    Depending on exactly what you’re trying to alert, it may be easier to just use a saved search?

    If not, SS2.0 (straight out of David Smith’s search export Chrome extension):

    Code:
    var employeeSearchObj = search.create({
    type: “employee”,
    filters:
    [
    [“role”,”anyof”,”3″]
    ],
    columns:
    [
    search.createColumn({
    name: “entityid”,
    sort: search.Sort.ASC,
    label: “Name”
    }),
    search.createColumn({name: “email”, label: “Email”}),
    search.createColumn({name: “title”, label: “Job Title”})
    ]
    });
    var searchResultCount = employeeSearchObj.runPaged().count;
    log.debug(“employeeSearchObj result count”,searchResultCount);
    employeeSearchObj.run().each(function(result){
    // .run().each has a limit of 4,000 results
    return true;
    });

  • #17979

    vkwanengage

    Thanks dominicb

  • #17980

    TheUsualSuspect

    Adding to dominicb answer somewhat. You can create a dynamic Group in NetSuite for employees with administrator roles and load the record in script using the ‘entitygroup’ record type. The only real benefit over a direct saved search is some easier management / maintenance for non-technical users in case additional criteria or special cases develop.

    Code:
    getEmailRecipients: function(entityGroup) {
    log.debug({ ‘title’: ‘Entity Error Group Id’, ‘details’: entityGroup });
    if (entityGroup) {
    var entityGroupRec = record.load({ type: ‘entitygroup’, id: entityGroup });
    var memberCount = entityGroupRec.getLineCount(‘groupmembers’);
    var emailList = [];
    for (var i = 0; i <= memberCount; i++) {
    var email = entityGroupRec.getSublistValue({ sublistId: 'groupmembers', fieldId: 'memberemail', line: i });
    if (email) { emailList.push(email); }
    }
    }
    log.debug({ 'title': 'List of recipients', 'details': JSON.stringify(emailList) });
    return emailList.toString();
    }

You must be logged in to reply to this topic.