Dynamic field value for name of template table???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2016 11:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2016 06:45 PM
Thank you for the very helpful instructions Stijn. But I'm still running into a problem. I have the reference field on the form, but it is hidden by a UI policy. When I apply the template to copy all attachments from the template to the incident nothing happens, or if I just have the field set to read-only. If I have the UI policy inactive then it works like a charm. I have set up a BR on my Incident table to do the copying of attachments. Is there something with a reference field
-- [Incident] after_BR When to run --
-- [Incident] after_BR Script --
Would this conflict with your script on the template table? I have also changed the reference field to a string field (read-only) for my Template Applied (u_template) and it's not filling in.
Thank you for all of your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2016 10:29 AM
Hi William,
I understand better now what you're trying to do
Ignore my Applied Template of field type being String in my last post... Indeed, you need a Reference field on the Incident level; you're right.
So what to do now:
(1) Make sure you have an "Applied Template" field of the type Reference, with the technical name u_applied_template on your Incident form. Don't change the field type of the existing field, rather delete the existing one and re-add it.
If the technical name of your re-created field would differ from u_applied_template; change in the script of the Business Rule Update Template Condition (see my last post) "u_applied_template" with "name_of_your_re-created_reference_field".
(2) Change in the script of the Update Template Condition Business Rule current.name to current.sys_id.
(3) In the script of your Copy template attachment to incident Business Rule; change current.u_template with current.name_of_your_re-created_reference_field.
Then it should work,
Stijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2016 08:16 AM
Hi stijn.verhulst, I am back at this as I never got it working the first time. I am going through this post again and trying to recreate it on our instance after upgrading to Geneva, and am running into some issues. The Applied Template reference field (u_applied_template) on the incident is not filling in with the template name when applying the template. Would it be too much trouble to ask you to take another look at this?
When I apply my test template to the incident, I don't get any conflicts, it says it applied successfully. But after saving the Applied Template name is not filled in.
Thank you!
-- Applied Template field info --
-- Incident BR Conditions --
-- Incident BR Script --
(function executeRule(current, previous /*null when async*/) {
//This function will be automatically called when this rule is processed.
var systemp = current.u_applied_template;
var thisRec = current.sys_id;
// Add your code here
GlideSysAttachment.copy('sys_template', systemp, 'incident', thisRec);
})(current, previous);
-- Template BR Conditions --
-- Template BR Script --
(function executeRule(current, previous /*null when async*/) {
current.template = 'u_applied_template' + current.sys_id + '^' + current.template;
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2016 12:38 PM
I think maybe I am having bigger issues here. For some reason when I am saving my template it keeps adding Activity Due. And, when I run the template on the incident, nothing happens. The caller doesn't change, the comments don't get applied, and the template applied reference field (that I've deleted and readded (u_template_applied) is not filling in. I'll put some screenshots and hopefully we can continue to work on this and finish this issue. Thanks for all your help stijn.verhulst!
-- Template form --
-- [Incident] BR Script -- (AFTER Insert, Update)
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
var systemp = current.u_template_applied;
var thisRec = current.sys_id;
// Add your code here
GlideSysAttachment.copy('sys_template', systemp, 'incident', thisRec);
}
-- Template BR Script -- (BEFOREUpdate)
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
current.template = 'u_template_applied' + current.sys_id + '^' + current.template;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2016 09:06 AM
My apologies for submitting this too soon. It appears to be working. I found where I missed the = in the template BR script from back the original post. current.template = 'u_applied_template' [...] should be current.template = 'u_applied_template=' [...].
It seems to be fixed now, just had to apply a UI policy to hide the applied template field, if number is anything, so the users don't see it.
To recap, the overview for this is as follows...
- Add a Reference field to the Incident [incident] form, e.g. "Applied Template (u_applied_template), referencing the Template table.
- Add a Yes/No field to the template form called "Add attachments to incidents" - the only applies the attachments to the Incident if this is true, and allows for the template to still function, but does NOT add the attachments to the related template table.
- Create an before Update BR on the template table [sys_template] with the following script which DYNAMICALLY fills in the applied template field with the name of the applied template, this gets added to the template form.
- Add a condition that says: Add attachments to incidents | IS | true
-- Template BR Script -- (BEFOREUpdate)
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
current.template = 'u_template_applied=' + current.sys_id + '^' + current.template;
}
- Add an after Insert, Update BR on the incident table [incident] with the following script. This will copy the attachment from the applied template to the incident.
- Add a condition for: Applied Template | changes - this will restrict from adding the same template more than once.
-- [Incident] BR Script -- (AFTER Insert, Update)
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
var systemp = current.u_template_applied;
var thisRec = current.sys_id;
// Add your code here
GlideSysAttachment.copy('sys_template', systemp, 'incident', thisRec);
}