Motivation
There was a question in the community as to how we can send out custom messages in the cloud factory and have them as part of the job logs. Below is my attempt to explain how we can do it.
Main Content
Let’s directly get into the technical details. First define a Messages objects containing arrays, each one for Error, Information and Warnings, as below: – Please note: Better to define this in the first step of the scenario execution, so that you can start capturing in the subsequent steps.
rootData.Messages = { Error:[],
Warnings:[],
Info:[]
};
Now to collect the messages in the respective arrays, we will use the core class Ctx.Iterator method “push”. It will be used as below.
//capture error
var text = 'This is an error';
rootData.Messages.Error.push(text);
//capture information
text = 'This is an information';
rootData.Messages.Info.push(text);
Basically, it is used to append an additional element to the array. So, you could keep adding the messages in each of the array as per the scenario need.
Now, on carefully observing the Cloud factory logs, we realize that it is the snapshot of the variable “rootData”. And yes, we created our “Messages” object as part of the “rootData”. This way, we will get our “Messages” object in the cloud factory log automatically.
Another way: –
With the above way, you will get the messages at the bottom of the entire log, after all the page related item content is printed. If you are lazy like me to scroll down, then define similar structure in the context of the workflow as the first folder separately as below: –
Fill the messages in that context as per the above method and you will not be required to scroll ?
Conclusion:
Create an additional data variable in “rootData” for messages and that will automatically come up in the logs of cloud factory