- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2014 03:33 AM
Hi there
I'm need of a little help relating to gliderecords.
Senerio
From the incident form, I want to add a 3rd part name and send an email to that 3rd party from an icon, so I have created a UI Macro for it. I can't seem to get the support email address from the core_company table to populate....
var sysID = g_form.getValue('u_3rd_party_name');
alert("Sys_ID of the 3rd party name - " +sysID); // This comes up correct
var suppEmail = ' ';
var myObj = new GlideRecord('core_company');
myObj.addQuery('name','=','sysID');
myObj.query();
while (myObj.next()) {
suppEmail = myObj.u_support_email_address;
}
alert("This is the suppEmail address returned - " +suppEmail); // This still shows blank
Can someone help me out where I am going wrong please? I don't think its fetching any records back, but I;ve tried numerous ways and still no joy (I'm new to Java)
Thank you in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2014 07:12 AM
Just realized you are searching the company table where Name = SysID. This won't work, try this code instead. Notice I changed it to search sys_id = sysID and btw you don't need the "=" in the addQuery.
var sysID = g_form.getValue('u_3rd_party_name');
alert("Sys_ID of the 3rd party name - " +sysID); // This comes up correct
var suppEmail = ' ';
var myObj = new GlideRecord('core_company');
myObj.addQuery('sys_id', sysID);
myObj.query();
retRows = myObj..getRowCount();
gs.log("returned number of rows = " +retRows);
while (myObj.next()) {
suppEmail = myObj.u_support_email_address;
}
alert("This is the suppEmail address returned - " +suppEmail); // This still shows blank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2014 04:08 AM
i guess this should work with
myObj.addQuery('name','=',sysID);
instead of myObj.addQuery('name','=','sysID');
as sysID is already a variable to put into the query string/function.
Let me know if this worked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2014 06:50 AM
I tried that already but the suppEmail still comes up blank.
I tried to get it to print to the log how many rows it returned, but it failed to even excute then, I used:
var sysID = g_form.getValue('u_3rd_party_name');
alert("Sys_ID of the 3rd party name - " +sysID); // This comes up correct
var suppEmail = ' ';
var myObj = new GlideRecord('core_company');
myObj.addQuery('name','=','sysID');
myObj.query();
retRows = myObj..getRowCount();
gs.log("returned number of rows = " +retRows);
while (myObj.next()) {
suppEmail = myObj.u_support_email_address;
}
alert("This is the suppEmail address returned - " +suppEmail); // This still shows blank
Did I put it in the wrong place?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2014 07:12 AM
Just realized you are searching the company table where Name = SysID. This won't work, try this code instead. Notice I changed it to search sys_id = sysID and btw you don't need the "=" in the addQuery.
var sysID = g_form.getValue('u_3rd_party_name');
alert("Sys_ID of the 3rd party name - " +sysID); // This comes up correct
var suppEmail = ' ';
var myObj = new GlideRecord('core_company');
myObj.addQuery('sys_id', sysID);
myObj.query();
retRows = myObj..getRowCount();
gs.log("returned number of rows = " +retRows);
while (myObj.next()) {
suppEmail = myObj.u_support_email_address;
}
alert("This is the suppEmail address returned - " +suppEmail); // This still shows blank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2014 07:34 AM
Fantastic thank you! I had to comment out the retRows bit though as it failed to do anything with those there... not sure why! But the correct results are seen, thank you for your help on this:)
Just another quick question, on the same UI Macro, I want to update a field on the incident table that isnt shown on the form.
At the moment it works because I have added the field on the form, but hidden it with a UI policy (I know, not the right way to do it)
So I wanted to do a little coding in my UI macro to update the field so I didnt have to use the UI policy to hide it and then I can remove it from the personlised form layout.
Its an instructions field, so once the UI Macro has got the support email address, I have a prompt box which is shown to the user for them to add instructions to the 3rd party. This is it currently.
if (suppEmail == ''){
g_form.showErrorBox("u_3rd_party_name.u_support_email_address", "A valid support email address is required before an email can be sent. Please contact the ServiceNow team for further details");
}
//Else pop open a 'enter 3rd party instruction' prompt box to write instructions for a 3rd party
else{
var third =prompt('Please enter your instructions to the selected 3rd party below:' , 'Type instructions here');
}
{
var notes = g_form.getValue('u_3rd_party_instructions');
var u_3rd_party_instructions = third;
g_form.setValue('u_3rd_party_instructions', u_3rd_party_instructions );
return true;
}
Its the field in BOLD that I need to remove off the form and remove the UI policy for. I think I need another glidrecord? find the record relating the the incident sys_id then myObj.update()? Is something like it should be?
var myObj2 = new glideRecord('incident');
myObj2.addQuery(current.sys_id);
myObj2.u_3rd_party_instructions = u_3rd_party_instructions;
myObj2.update();