- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2015 04:18 AM
There is a UI action on my Knowledge Management form which is named as Create Article and it creates an article from the form upon clicking. Below is the snippet of the code which I am finding difficult to understand, would someone like to explain it for me.
--------------------------------------------------------------------------------------------------
if (current.hasAttachments()) {
var ids = GlideSysAttachment.copy('kb_submission', current.sys_id, 'kb_knowledge', gr.sys_id);
ids = ids.toArray();
for (var i = 0; i < ids.length; i++) {
var oldandnew = ids[i].split(',');
gr.text = gr.text.toString().replaceAll(oldandnew[0],oldandnew[1]);
}
}
---------------------------------------------------------------------------------------------------
The code written in the FOR loop is ambiguous for me, thanks a lot for any help!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2015 06:33 AM
Yes Chris, Your guess is absolutely right
In the script above there is a statement [gr.text = current.text;] which is copying the contents of Text field from KB Submission record and pasting as it is in new KB article (going to be created) Text field. Now that, if KB Submission record had attachments then Text field contents include the URLs pointing to sys_attachment record but for KB Submissiion.
Therefore, with statement [gr.text = gr.text.toString().replaceAll(oldandnew[0],oldandnew[1]);], script is replacing those sys_attachment sys_id's with the new sys_ids (from sys_attachment record) which are created for KB article.
@Gourav : I tried explaining it as simple as possible. Please let me know if you are clear with the logic?
Brgds, AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2015 08:41 AM
Thank you both to Chris Martin and Antony for your detailed explanation. Thank you once again.