How to delete leftover script parameters when the ...
# ask-stanley-ai
t
How to delete leftover script parameters when the script record is deleted already
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems that you cannot directly delete script parameters when the script record is already deleted. However, you can use a workaround to achieve this. You can use a User Event (UE) script to trigger code when a record is deleted. In the
afterSubmit
function of the UE script, you can perform the necessary operations to delete the leftover script parameters. However, it's important to note that the
context.request.parameters
object, which is used to access URL parameters, is only available in the
beforeLoad
function. Therefore, you might need to store the URL parameters in a scripted field in the
beforeLoad
function, and then reference this field in the
afterSubmit
function. Here is a rough idea of how you can do this:
Copy code
javascript
function beforeLoad(context) {
    if (context.type === context.UserEventType.DELETE) {
        // Store the URL parameters in a scripted field
        var urlParameters = context.request.parameters;
        context.newRecord.setValue({
            fieldId: 'custrecord_url_parameters',
            value: JSON.stringify(urlParameters)
        });
    }
}

function afterSubmit(context) {
    if (context.type === context.UserEventType.DELETE) {
        // Retrieve the URL parameters from the scripted field
        var urlParameters = JSON.parse(context.newRecord.getValue({
            fieldId: 'custrecord_url_parameters'
        }));

        // Perform the necessary operations to delete the leftover script parameters
        // ...
    }
}
Please note that this is a general idea and you might need to adjust the code according to your specific needs. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.827532113
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.80382055
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.803522229
Please provide your feedback on this answer.