widget on service portal

suresh101
Tera Contributor

I have created widget on service portal
in the body html template I have added few fields like caller, category, contact type, description and short description along with submit button
if i click the submit  button new tab should be open  incident form with pre filled above details, need to save incident form manually
in the client controller I have added beow script

$scope.submitForm = function () {
        var callData = {
caller_id: $scope.data.caller,
category: $scope.data.category,
contact_type: $scope.data.contact_type,
short_description: $scope.data.short_description,
description: $scope.data.description
        };
 
after this how to write a script for incident open on new tab, prefilled values
12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

@suresh101 

share the html code as well and also the complete client controller

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@suresh101 

try this

$scope.submitForm = function () {
    var callData = {
        caller_id: $scope.data.caller,
        category: $scope.data.category,
        contact_type: $scope.data.contact_type,
        short_description: $scope.data.short_description,
        description: $scope.data.description
    };

    // Construct the URL with query parameters
    var url = '/incident.do?sys_id=-1' +
        '&sysparm_query=caller_id=' + encodeURIComponent(callData.caller_id) +
        '^category=' + encodeURIComponent(callData.category) +
        '^contact_type=' + encodeURIComponent(callData.contact_type) +
        '^short_description=' + encodeURIComponent(callData.short_description) +
        '^description=' + encodeURIComponent(callData.description);

    // Open the URL in a new tab
    window.open(url, '_blank');
};

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar 
all values are populating except caller_id

@suresh101 

caller_id field is reference to sys_user so it requires sysId of user.

is the input type in HTML giving you sysId or string?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader