Targeted Communication- Populate recipient list via script

Wasif
Giga Guru

Hi all,

We were wanting to populate the recipient list in Targeted communication using script.
We wrote a script mimicking the object required to put output from the function, but its not returing proper data in the recipient list. 
(In background script-its able to return an object format as specified in the script's comment section

Has anyone tried it or can direct to proper script object to return etc?

 

Sample Script added in the script section:

(function() {
    //This script is used to upload recipients to the recipients list based on type chosen 
    //Example: 
    //Script should have the type as the 'key' and array of sys_ids corresponding to the type as the values. 
    //internal => sys_user 
    //var obj = {'internal' : ['sysId1','sysId2','sysId3']}; 
    //return obj; 
    //var obj = {};
    var existingTranslationsArr = [];
    var grTrans = new GlideRecord('sys_user');
    grTrans.addEncodedQuery('user_nameISNOTEMPTY^active=true');
    grTrans.setLimit(10);
	grTrans.orderByDesc('created');
    grTrans.query();
    while (grTrans.next()) {
        existingTranslationsArr.push(grTrans.getValue('sys_id'));
    }
    var obj = {
        'internal': existingTranslationsArr
    };
    //gs.info(JSON.stringify(obj));
    return obj;


})();


The recipients which this script is ultimately adding is also attached in the attachment- which seems to be blank users, and also I specified 10 rows, it brings 6 rows. Not sure on that part as well...

If someone can help on this?

1 ACCEPTED SOLUTION

Wasif
Giga Guru

I changed the 'Type' of the Recipient list record to 'Contacts' and also updated the previous script json type from 'internal' to 'external' and then the script was able to populate the recipients.

View solution in original post

3 REPLIES 3

Anand Kumar P
Giga Patron
Giga Patron

Hi @Wasif ,

 

 

(function() {
    var existingTranslationsArr = [];
    var grTrans = new GlideRecord('sys_user');
    grTrans.addActiveQuery(); // Filter by active users.
    grTrans.orderByDesc('created'); 
    grTrans.setLimit(10);
    grTrans.query();
    while (grTrans.next()) {
        existingTranslationsArr.push(grTrans.getValue('sys_id'));
    }
    var recipientList = existingTranslationsArr.join(',');
    gs.info('Recipient List: ' + recipientList);
    return recipientList;
})();

 

Use above script to return list of sys_id.
Please mark it as accepted solution and helpful if it works for you.

Thanks,

Anand 

Mayur2109
Kilo Sage
Kilo Sage

Hi @Wasif ,

 

Script is working fine and list is also loaded correctly see the attachments.

Please check in user table if you are having the correct data that you are using in your query.

 

Please check and Mark Helpful and Correct if it really helps you.

Regards,
Mayur Shardul

Wasif
Giga Guru

I changed the 'Type' of the Recipient list record to 'Contacts' and also updated the previous script json type from 'internal' to 'external' and then the script was able to populate the recipients.