This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to load user's information from a SBM table to a created the SBM Role automatically

We have a SMB project, there is a table called Suppliers, which has hundreds of suppliers’ individual information. We also created a Supplier Role in this project. Instead of setting one person to Supplier Role group from the SBM workCenter manually, how can we load all individual information from the Suppliers table to Supplier Role automatically?

Thank you

Parents
  • 0  

    To clarify, in SBM, roles and groups are ways to assign privileges to users:

    • a role is created in Composer and attached to the application.
    • a group is defined in SBM Application Administrator.

    You can add users to either level, but I would recommend adding users to a group, and then assigning a group to a role. Groups are easier to manage privileges and you can run system reports to see who is in the group.

    To answer your question, if I understand correctly, the user accounts do not exist at all in SBM, but the user information is in the suppliers table. You want to add these individuals as actual users within SBM (note that this does require the appropriate additional user licenses for SBM).

    For adding new users, I usually resort to using an orchestration as I trust that functionality better. Here are the steps that i would take:

    1. I would create a group for your suppliers, associating the correct role with that group
    2. Create one supplier to act as a template user associate with group created in 1 and add any other additional information.
    3. Create an orchestration, which runs a report of all records in the suppliers table, and then create users for each record, using the template user created in step 2.

    Now if you already have the users in SBM and you just want to add them to the group, you can do the same as above, just updating the user account.

    If the users are already I added, I choose modscript to automatically add users. I use the following snippet often on transitions where a user is selected in a field, but may not yet be part of the correct permission group to own the item yet. The script searches for the group by name, and if that particular userId is not in the group, then it adds it.

    def addToGroup(userId){
        var groupName = "Group Name";
        //check if member
        var group = Ext.CreateAppRecord (Ext.TableId("TS_GROUPS"));
        group.ReadWithWhere("TS_NAME='${groupName}'");
        var grpId = group.GetId();
            
        var member = Ext.CreateAppRecord (Ext.TableId("TS_MEMBERS"));
        var qs2 = "TS_USERID = ${userId} AND TS_GROUPID = ${grpId}";
        if(!member.ReadWithWhere(qs2)) {
            // add to member
            member.SetFieldValue("USERID",userId);
            member.SetFieldValue("GROUPID", grpId);
            member.SetFieldValue("ESTABLISHEDBY", 0);
            var ret = member.Add();
            if (ret == 0){
                return "Error adding to group ${groupName}.<br/>";
            } else {            
                return "Added to group ${groupName}.<br/>";
            }
        } else {
            return "";
        }
        
    }

  • 0 in reply to   

    Hi Michael,

    Thank you so much for your detailed response. I have created the Modscript you showed here on transitions where a user is selected in a field. I have tried the Modscript, but had validation issue. Error: "Illegal character" in 'Add Supplier'  at (2, 1). I used the Group name called "SPQ_Training_Supplier" that defined in Application Administrator. 

    This is the Group name defined in Application Administrator:

    This is the Modscript where I called in the transition:

  • 0 in reply to 

    Data that is copied from web pages and pasting into a script can have problems.  This is frequently because "DOUBLE QUOTE" characters are not ASCII character 34.

    Edit the script in Composer and replace the characters that look like double-quote with actual double-quote characters.

  • Verified Answer

    +1   in reply to 

    I agree. Cutting and pasting script from other sources can introduce problematic characters. In addition to the double quotes, I have found problematic characters for blank spaces.

    First, try the validate script button to see if Composer can find the error, which sounds like it is in line 2. As   recommended, edit the script in composer and see if the errors are removed.

    Second, I've also had to paste code into Notepad++ to find the illegal characters. After pasting code into a new page, select to show all characters in Notepad++, and then you may see some invalid ASCII characters.

Reply
  • Verified Answer

    +1   in reply to 

    I agree. Cutting and pasting script from other sources can introduce problematic characters. In addition to the double quotes, I have found problematic characters for blank spaces.

    First, try the validate script button to see if Composer can find the error, which sounds like it is in line 2. As   recommended, edit the script in composer and see if the errors are removed.

    Second, I've also had to paste code into Notepad++ to find the illegal characters. After pasting code into a new page, select to show all characters in Notepad++, and then you may see some invalid ASCII characters.

Children
  • Verified Answer

    +1 in reply to   

    Hi Micheal, 

    I have reloaded the Modscript you provided. and there are no invalidation issues, but the users in Supplier table aren't added to the Supplier group.

    1.        2. 

    For example, the user Lynda - Lynn showed in "graph 1" is the user in the Auxiliary Supplier table. I want to add this user into the Supplier group showed in "graph 2" after selecting the user from "graph 1".