How to use a Custom Skill LLM out put in a Client script

SamirNyra
Tera Contributor

I have written a sample hard-coded script to have a client script that shows a message on submit to suggest that the quality of the incident description needs to be improved. How can I define the below highlighted variable so that it is using the score from the LLM model output? Do see the screenshot attached? 

 

// Client Script: onSubmit
// Table: Incident
// Type: onSubmit

function onSubmit() {
    // Example: Replace this with the actual way you get the model_output from your Now Assist skill
    var model_output = "{\"model_output\":\" Score: 3\\nQuality: Poor\\n\"}";

    // Parse the JSON string
    var parsed = JSON.parse(model_output);
    var output = parsed.model_output; // " Score: 3\nQuality: Poor\n"

    // Extract lines
    var lines = output.split('\n');
    var score = lines[0].split(':')[1].trim();    // "3"
    var quality = lines[1].split(':')[1].trim();  // "Poor"

    // If quality is Poor, show message and block submission
    if (quality.toLowerCase() === "poor") {
        g_form.showFieldMsg('description', "Please add more details to your description.", "error");
        return false; // Prevent insert/update
    }

    return true; // Allow insert/update
}
1 REPLY 1

Mark Manders
Tera Patron

I am not 100% sure when this is evaluated, but are you sure it is client side? Is the output available before the record is submitted to the server?