Create a import set and load data from JSON
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 04:39 AM
Hi,
I have a JSON file which I am using to create a RITM and add an attachment to the created ticket in base64 format through postman. I want to run a transform map on the file so that the attachment will do that mandatory check for the data before creating the record.
For sample: The excel file has two columns:
Device Name IP address
So the transform map which have been created has mandatory checks while load data (should not be empty). The same should be replicated while creating through postman. The response should throw an error.
can anyone guide me on how to achieve this through script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 05:24 AM
Hi @tanz
First, create a Script Include that will validate the attachment data before creating the record.
This Script Include should accept the attachment data and perform the necessary validation.
var AttachmentValidator = Class.create();
AttachmentValidator.prototype = {
initialize: function () {},
// Validate attachment data
validateAttachment: function (attachment) {
if (!attachment || !attachment.payload) {
return "Attachment payload is missing or empty.";
}
// Perform additional validation checks as needed
return null; // Return null if validation is successful
},
type: "AttachmentValidator"
};
You can use a Business Rule on the target table (e.g., RITM) that runs before insert. In the Business Rule script, you can instantiate the AttachmentValidator and call the validateAttachment method.
(function executeRule(current) {
var attachmentData = current.getValue('attachment_field'); // Replace 'attachment_field' with the actual field name
var validator = new AttachmentValidator();
var validationError = validator.validateAttachment(attachmentData);
if (validationError) {
// Attachment data is invalid, set an error message and prevent record creation
gs.addErrorMessage(validationError);
current.setAbortAction(true);
}
})(current);
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar