- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 01:16 AM
Hi All,
I have a system property where the data has been define like this ( array of objects format ):::
{
"email1@abc.com":["8452de8f8394865050ed47747daad391","Value 1.0"], //group1,version1
"email2@abc.com":["8965de9f8394811050edk7747daad391","Value 2.0"], //group2,version2
}
Using Inbound Action, I am trying to populate couple of fields by referring to this system property above, like this:::
var group = gs.getProperty('Email To Group Mapping');
var grp = JSON.parse(group);
var email_to = email.to;
email_to = email_to.toLowerCase();
email_to = email_to.split(',');
for (i = 0; i < email_to.length; i++) {
if (email_to[i].includes('email')) {
current.assignment_group = grp[email_to[i][0]];
current.u_version = grp[email_to[i][1]];
gs.info("Assignment Group: " + current.assignment_group);
gs.info("Version: " + current.u_version);
}
}
But unfortunately both the Assignment Group and Version is returning false! Can someone please help me to debug this piece or logic?
Thanks and Regards,
Saurabh Chatterjee
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 07:48 AM
Hi @chatsaurav19
No Worries , here i have updated the code logic as per your system property obj.
Code :
var group = gs.getProperty('Email.To.Group.Mapping'); //Your Own Sys Property
var group_p = JSON.parse(group);
gs.info("Saurabh Group: " + JSON.stringify(group_p));
var email_to = email.to;
email_to = email_to.toLowerCase().split(',');
gs.info("Saurabh Email: " + email_to);
for (var i = 0; i < email_to.length; i++) {
var emailKey = email_to[i].trim();
gs.info("Saurabh Email Key: " + emailKey);
gs.info("Saurabh Email Key PROP: " + group_p.hasOwnProperty(emailKey));
gs.info("Saurabh Email Key KEY LENGTH: " + group_p[emailKey].length);
if (group_p.hasOwnProperty(emailKey) && group_p[emailKey].length == 2) {
current.assignment_group = group_p[emailKey][0];
current.u_cockpit_version = group_p[emailKey][1];
gs.info("Saurabh Assignment Group: " + current_assignment_group);
gs.info("Saurabh Version: " + current_u_cockpit_version);
}
}
Note :
The "emailKey" is "abc.ab11.def@qwe.com", the key corresponding to the email address. The length of the array associated with this "emailKey" is 2 because there are two elements in the array: "8452de8f8394865050ed47747daad391" and "Value 1.0". Therefore, group_p[emailKey].length would evaluate to 2.
BG Script Code :
System Property SS :
Please mark my answer helpful and correct.
Regards,
Subhashis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 05:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 06:30 AM - edited 03-22-2024 06:34 AM
You can use your own variable name and updated the System property name in code logic (Email.To.group.mapping).
var group = gs.getProperty('Email.To.Group.Mapping'); //Your Own Sys Property
var group_p = JSON.parse(group);
gs.info("Saurabh Group: " + group_p);
var email_to = email.to;
email_to = email_to.toLowerCase().split(',');
gs.info("Saurabh Email: " + email_to);
for (var i = 0; i < email_to.length; i++) {
var emailKey = email_to[i].trim();
gs.info("Saurabh Email Key: " + emailKey);
if (group_p.hasOwnProperty(emailKey) && group_p[emailKey].length > 2) {
current.assignment_group = group_p[emailKey][0];
current.u_cockpit_version = group_p[emailKey][1];
gs.info("Saurabh Assignment Group: " + current.assignment_group);
gs.info("Saurabh Version: " + current.u_cockpit_version);
}
}
Use 'dot' for System Property naming convention, for example, 'Email.To.group.mapping' like this.
For ref :
Please mark my answer helpful and correct.
Regards,
Subhashis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 07:11 AM
Surprisingly when I tried checking this condition, I got 'false' and 'undefined' respectively.
if (group_p.hasOwnProperty(emailKey) && group_p[emailKey].length > 2)
Length is : undefined
Property is: false
Regards,
Saurabh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 07:48 AM
Hi @chatsaurav19
No Worries , here i have updated the code logic as per your system property obj.
Code :
var group = gs.getProperty('Email.To.Group.Mapping'); //Your Own Sys Property
var group_p = JSON.parse(group);
gs.info("Saurabh Group: " + JSON.stringify(group_p));
var email_to = email.to;
email_to = email_to.toLowerCase().split(',');
gs.info("Saurabh Email: " + email_to);
for (var i = 0; i < email_to.length; i++) {
var emailKey = email_to[i].trim();
gs.info("Saurabh Email Key: " + emailKey);
gs.info("Saurabh Email Key PROP: " + group_p.hasOwnProperty(emailKey));
gs.info("Saurabh Email Key KEY LENGTH: " + group_p[emailKey].length);
if (group_p.hasOwnProperty(emailKey) && group_p[emailKey].length == 2) {
current.assignment_group = group_p[emailKey][0];
current.u_cockpit_version = group_p[emailKey][1];
gs.info("Saurabh Assignment Group: " + current_assignment_group);
gs.info("Saurabh Version: " + current_u_cockpit_version);
}
}
Note :
The "emailKey" is "abc.ab11.def@qwe.com", the key corresponding to the email address. The length of the array associated with this "emailKey" is 2 because there are two elements in the array: "8452de8f8394865050ed47747daad391" and "Value 1.0". Therefore, group_p[emailKey].length would evaluate to 2.
BG Script Code :
System Property SS :
Please mark my answer helpful and correct.
Regards,
Subhashis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 08:42 AM
Thank you @Subhashis Ratna for your patience and help! It worked! Thanks a lot!