Record producer

Community Alums
Not applicable

Hello Team,

 

I have request to create 4 tasks under record producer on the basis of condition:-

 

e.g:- Suppose I have drop down list having options A,B,C,D  when I have selected   option A then Automation task needs to be create for assignment group A.

Same for other options B, C and D as well . Could you please help how we can create those tasks,.

 

Please let me know below how we achieve though below:- how we can achive this  script.

 

ooo_0-1732610886666.png

 

 

9 REPLIES 9

mahemoodhus
Tera Contributor

Hi @Community Alums 

Here is the answer you can write a catalog client script to achieve this below I write the code 

function onSubmit() { var choice = g_form.getValue('assignment_group_choice'); // Dropdown field // Create tasks based on choice var taskGr = new GlideRecord('sc_task'); // Task table if (choice == 'A') { taskGr.initialize(); taskGr.short_description = 'Automation task for Group A'; taskGr.assignment_group = 'Assignment Group A'; // Replace with the correct Sys ID of the assignment group taskGr.insert(); } else if (choice == 'B') { taskGr.initialize(); taskGr.short_description = 'Automation task for Group B'; taskGr.assignment_group = 'Assignment Group B'; // Replace with the correct Sys ID of the assignment group taskGr.insert(); } else if (choice == 'C') { taskGr.initialize(); taskGr.short_description = 'Automation task for Group C'; taskGr.assignment_group = 'Assignment Group C'; // Replace with the correct Sys ID of the assignment group taskGr.insert(); } else if (choice == 'D') { taskGr.initialize(); taskGr.short_description = 'Automation task for Group D'; taskGr.assignment_group = 'Assignment Group D'; // Replace with the correct Sys ID of the assignment group taskGr.insert(); } return true; // Ensure the record producer form submits
Let me know if you have any doubt and If my response prove useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

AndersBGS
Tera Patron
Tera Patron

Hi @Community Alums ,

 

Why a record producer instead of a catalog item? If you create a catalog item you can attach the flow from flow designer directly to the single item. Simplified, record producers is just about creating single record in specific table. 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Community Alums
Not applicable

@AndersBGS  Hv u read my Question carefully , I am creating record producer . instead of doing unnecessary Commets . Try to read and ans my Question. 

 

Thanks  

Hi @Community Alums ,

 

I did read your question  and also provided a valid comment. Did you read my comment through? Instead of just providing what you're asking, i'm instead questioning your approach. Off course, if you think that your approach that you have decided on is the only source of truth, then just disregard the comment and script away. 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Community Alums
Not applicable

Hi   @Community Alums ,

We can achieve this using a Client Script and Script Include. You can try the following code. It works, but make sure to change the values according to your needs.

1)on submit client script

function onSubmit() {
    var selectedOption = g_form.getValue('dropdown_choice'); // Replace with your variable name

    // Call Script Include via GlideAjax
    var ga = new GlideAjax('TaskCreationHelper');
    ga.addParam('sysparm_name', 'createTask');
    ga.addParam('sysparm_selectedOption', selectedOption);
    ga.getXMLAnswer(function(response) {
        if (response === 'success') {
            gs.addInfoMessage('Task created successfully.');
        } else {
            gs.addErrorMessage('Failed to create task.');
        }
    });

    return true; // Allow form submission
}

 

 script include

var TaskCreationHelper = Class.create();
TaskCreationHelper.prototype = {
    initialize: function() {},

    createTask: function(selectedOption) {
        var groupMapping = {
            'A': 'sys_id_of_group_A',  // Replace with actual sys_id
            'B': 'sys_id_of_group_B',  
            'C': 'sys_id_of_group_C',  
            'D': 'sys_id_of_group_D'   
        };

        var assignmentGroup = groupMapping[selectedOption];
        if (assignmentGroup) {
            var taskGR = new GlideRecord('task'); // Use 'incident' or 'sc_task' if needed
            taskGR.initialize();
            taskGR.short_description = 'Automation Task for Option ' + selectedOption;
            taskGR.assignment_group = assignmentGroup;
            taskGR.insert();
            return 'success';
        } else {
            return 'failure';
        }
    },

    type: 'TaskCreationHelper'
};

 

Thank You @Community Alums ...!