All the required permissions are in place for the script to run.
The script is collecting the data.
But the data is not being mapped to the attributes and thus is not being shown in the incident.
There were some blank spaces in the script which caused the data to not be mapped to the attributes.
After removing those blank spaces, the data was correctly mapped to the attributes and displayed in the incident.