Accessing the to‐be sys_id on a catalog item - jcmings/sn GitHub Wiki

In light of a series (1 | 2) of recent Community threads asking how to get the sys_id of the current catalog item before it gets submitted, I wanted to capture the process here, just in case those Community posts disappear. So this post is effectively just a keep-safe.

Note -- I am literally copy and pasting from a Community user named Nick Parsons. Thank you Nick for describing how to do this.

I have tested the second one; you simply just pop this into a catalog client script.

Get an array of attachments

You can get an array of attachments in a catalog client script by inspecting the angular scope like so:

var $scope = this.angular.element("#sc_cat_item").scope();
var attachmentSysIds = $scope.attachments.map(function(attachmentDetails) {
  return attachmentDetails.sys_id;
});
// Result is an array of sys_attachment sys_ids: 
// ["5cf0d22453b9121036a838f0a0490e55", ...]

Get the sys_id of the to be record

You can get the sys_id of the record that's about to be generated by also looking at the angular scope, but at different properties:

var $scope = this.angular.element("#sc_cat_item").scope();
var toBeTableName = $scope.data._attachmentTable;
var toBeSysId = $scope.data._generatedItemGUID;
// Result is the record the Record Producer is going to create, for Catalog Items, this is the `sc_cart_item` record:
// toBeTableName = incident 
// toBeSysId = 2943522053f9121036a838f0a0490e78
// You can query the sys_attachment table's `table_name` and `table_sys_id` fields that match the above to find the attachments uploaded.