Calling multiple users in a loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2024 12:05 AM
Hi,
I have a requirement where single/multiple users will be given in a field (comma separated) and I have to take the users and execute all of them in a loop of rest message , each user output will give 200 result. I am passing the user from the BR(after insert) where in the my custom table only one string field is there - User to be added(ex:a.b@gmail.com,b.c@gmail.com). I am trying to call the script include by passing the user field as parameter. I want to print the segregated user and print 200 against each user.
a.b@gmail.com 200
a.b@gmail.com 200
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2024 01:50 AM
@tanz - Please try with the below code
_getUser: function (email) {
try {
// email variable carries a field value a.b@gmail.com,b.c@gmail.com
// email = "a.b@gmail.com,b.c@gmail.com"
var userEmails = email.split(",");
var token = this._getToken();
if (JSUtil.nil(token)) {
return;
}
var resultArray = [];
for (var userEmailIndex; userEmailIndex < userEmails.length; userEmailIndex++) {
var userEmail = userEmails[userEmailIndex];
var r = new sn_ws.RESTMessageV2('API', 'Get User ');
r.setStringParameterNoEscape("token", token);
r.setStringParameterNoEscape('userEmail', "'" + userEmail + "'");
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var parsing = JSON.parse(responseBody);
var jsonObj = {
userSpecificID: '',
httpStatus: '',
responseBody: ''
};
jsonObj.userSpecificID = parsing.value[0].id + '';
jsonObj.httpStatus = httpStatus;
jsonObj.responseBody = parsing;
var result = userEmail + " " + httpStatus;
gs.info(result);
resultArray.push(result);
//return JSON.stringify(jsonObj);
}
/*returns the value
a.b@gmail.com 200
a.b@gmail.com 200"
Note: response code may not be 200 in case of failure in the result
*/
return resultArray.join("\n");
} catch (ex) {
var message = ex.message;
}
}
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2024 02:07 AM
@tanz Create script include and put "_getUser: function(email) " code into it. Write below code in BR and call script include
var emails = current.custom_email_field + ''; // put your custom field name here
var userEmails = emails.split(',');
userEmails.forEach(function(index){
var output = new scriptIncludeName._getUser(index);
})
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!