During Live Coding Happy Hour (LCHH) last week session about Decision APIs I got intrigued when Earl Duque used gr.getValue(‘sys_id’) instead of gr.getUniqueValue(), and in the comments was mentioned getUniqueValue() does not always return the sys id, so lets confirm that.
Lets take a look at the API Documentation says (here).
It says “get the primary key of the record which is usually sys_id unless otherwise specific”. Interesting, what they mean by primary key of a record? There’s a field called “Primary” that is only true for the Sys ID.
Made “PK” field as primary, did a quick GlideRecord query() and it always returned the sys id. I couldn’t prove their hypothesis – getUniqueValue is returning always the sysId. What did I miss?
It seems you can have multiple fields with primary = true (?).
var grTest = new GlideRecord('x_299742_nowjedi_example');
grTest.query();
while (grTest.next()) {
gs.info(grTest.getUniqueValue());
}
If you know the answer to this please drop in the comments.
How many times did you write the code to find the previous value on a specific field? Long time ago I found a library called “HistoryWalker” and since then its been on my must-have snippets on my utils. This library sn_hw is not “public” available but you can see lot of scripts using it. Quite useful 🙂
getHistoryWalker: function(grObject,field) {
var answer = [];
var previousValue;
var hw = new sn_hw.HistoryWalker(grObject.getRecordClassName(), grObject.getUniqueValue());
hw.walkTo(grObject.sys_mod_count);
do {
var wr = hw.getWalkedRecordCopy();
var currentValue = wr.getValue(field);
if (currentValue != previousValue) {
previousValue = currentValue;
answer.push(wr.getValue(field) + '');
}
} while (hw.walkBackward());
return answer;
},
The article below is intended for any person customise your Workflows. Javascript knowledge is useful but not required.
As I mentioned in other articles, regardless of your task, there aren’t always enough hours in the day to get everything done. As a result, you constantly feel like you’re always behind. And that’s just not good for your productivity or your health. Instead of putting in those extra hours, you can become more effective at work by focusing on what really matters. And you can get started with that ASAP by applying this quick scalable solution to your scripts.
Here’s a few things we will cover:
Use Case
Example
Automate properties (sys_properties)System properties store configuration information that rarely or never changes. Each time you change or add a system property, the system flushes the cache to keep all nodes in the cluster in synch. This cache flush has a very high performance cost for one to 10 minutes, which can potentially cause an outage if done excessively. To prevent such outages, do not use a system property to store configuration information that changes more than once or twice a month.
I usually identify what can change in the future, like “group id”, “names”, etc.
Use Case Walkthrough
In the Navigation filter, enter sys_properties.list.The entire list of properties in the System Properties [sys_properties] table appears.
Verify that the property does not exist by searching for the property name.
Click New. Usually I use “company.workflow.default.L1″.
Complete the System Property form. Type: String Value: <sys_user_group_id>
Navigate to Workflow > Workflow Editor
Edit your workflow and change script as appropriate.
Unfortunately there is no magic formula to identify which task or script or variable should be considered as system properties but to start you should think what can change over the time.
Example #1:
Found some quite simple use case in the communities (link). A user would like to add a IF condition in the workflow to verify if the sys_property value is equal to true and then, the requester assigned will be XXX company and eventually will fire the next sc task.
answer = ifScript();
function ifScript() {
var prop = gs.getProperty('ab.provision.workflow');
var comp = current.u_requestor.company.getDisplayValue(); //I am assuming u_requestor is the field company name
if (prop == 'true' && comp == 'company name') {
return 'yes';
}
return 'no';
}
Conclusion
System properties are not limited to just Notifications or Workflows, they’re part of the NOW Platform and can include anything we have in the Platform. Try to automate your instance and try to centralize all your “customer” data in one place. Use all the tools at your disposal to make that happen.
I will try to collect a use case for each type in order to help you to identify on which cases you should apply the sys property technique.
var p_dropdown = request.getParameter('dropdownId');
// For debugging
gs.info("MyDebug -INFO- Received form value for process ->" + p_dropdown);
gs.log("MyDebug -INFO- Received form, value for process ->" + p_dropdown);
"Being a Jedi is not just about power, or lightsabers, or even skill with the Force. It is about connection. Being part of something bigger. I am stronger as part of the Jedi Order than I could ever be alone."