Syntax for Glide Insert a field of Document ID Type

morgan_g
Kilo Contributor

Please help me work out the syntax for doing a glide insert on a field of document ID type?   It looks like it should be some combination of the table and sys ID but I'm not finding any examples on the wiki entries for glide nor document ID fields.

Specifically I've got a particular incident workflow and am trying to trigger publication to the live feed which contains a column called document that is of document ID type:

 
function add2LiveFeedFn()
{
          var instanceURL = gs.getProperty('glide.servlet.uri');
          workflow.scratchpad.baseURL = instanceURL;

var newProfile = new GlideRecord('live_profile');
          newProfile.initialize();
          newProfile.type='document';
          newProfile.document = current.sys_id; //Does not seem to work, nor does current.table_sys_id
          newProfile.document_table = 'incident';
          newProfile.image = 'majorincident.pngx';
          newProfile.name = 'MI: '+current.cmdb_ci.getDisplayValue();
          newProfile.insert(); 
          workflow.scratchpad.newProfile = newProfile.sys_id; 
          
          var newLiveFeedMessage = new GlideRecord('live_message');
          newLiveFeedMessage.initialize();
          newLiveFeedMessage.message='New Major Incident recording unscheduled outage: '+current.short_description;
          //newLiveFeedMessage.has_tags = 'true';
          newLiveFeedMessage.profile = newProfile.sys_id;
          //newLiveFeedMessage.reply_to = sys_id_of_original_post; //Will use this later to post a reply after the outage is resolved
           newLiveFeedMessage.state = 'published';
          
          newLiveFeedMessage.insert();
          workflow.scratchpad.liveFeed = newLiveFeedMessage.sys_id; 

          current.work_notes=("Publishing live feed link "   +'[code]   here for '+ current.short_description+'[/code] '); } add2LiveFeedFn(); 
1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Document ID fields require a table and the SysID of the record.   The column names do differ from table to table.   You are close in your code above, the only issue is you have newProfile.document_table (document_table is not a column in the live_profile table) where you should have newProfile.table.   So this should work:


var newProfile = new GlideRecord('live_profile');


newProfile.initialize();


newProfile.type='document';


newProfile.document = current.sys_id; //Does not seem to work, nor does current.table_sys_id


newProfile.table = 'incident';


newProfile.image = 'majorincident.pngx';


newProfile.name = 'MI: '+current.cmdb_ci.getDisplayValue();


newProfile.insert();


workflow.scratchpad.newProfile = newProfile.sys_id;


View solution in original post

3 REPLIES 3

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Document ID fields require a table and the SysID of the record.   The column names do differ from table to table.   You are close in your code above, the only issue is you have newProfile.document_table (document_table is not a column in the live_profile table) where you should have newProfile.table.   So this should work:


var newProfile = new GlideRecord('live_profile');


newProfile.initialize();


newProfile.type='document';


newProfile.document = current.sys_id; //Does not seem to work, nor does current.table_sys_id


newProfile.table = 'incident';


newProfile.image = 'majorincident.pngx';


newProfile.name = 'MI: '+current.cmdb_ci.getDisplayValue();


newProfile.insert();


workflow.scratchpad.newProfile = newProfile.sys_id;


Adding an insert with the table name (incident in this case) into a 'column' called table on the profile record did the trick.     (Also put in for an update on the Wiki talk page for document ID fields.)



Thank you very much!


Turns out in Knowledge v3 the table field on kb_category is parent_table instead of table for the parent_id (Document ID type field), for anyone who comes across this thread.     Digging into the dictionary entries by table seems to reveal where the table name is stored.



-mg