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

In HTML gave below code

<!-- Caller -->
<div class="form-group">
<label ng-if="data.company">Caller</label>
<input type="text" class="form-control" ng-if="data.company" ng-model="data.caller" ng-change="toggleCaller()">
</div>

@suresh101 

if user is entering full name then query sys_user, get the sysId and then include in URL

Something like this and enhance the query

$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
    };

    var callerSysId = '';
    var gr = new GlideRecord("sys_user");
    gr.addQuery("name", callData.caller_id);
    gr.query();
    if (gr.next()) {
        callerSysId = gr.getUniqueValue();
    }


    // Construct the URL with query parameters
    var url = '/incident.do?sys_id=-1' +
        '&sysparm_query=caller_id=' + encodeURIComponent(callerSysId) +
        '^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

I Have added below code as well but still caller is not populating 

 

   var callerSysId = '';
        var gr = new GlideRecord("sys_user");
        gr.addQuery("name", callData.caller_id);
        gr.query();
        if (gr.next()) {
            callerSysId = gr.getUniqueValue();
        }

  

@suresh101 

I informed to enhance the query based on what user enters

what is user entering? if it's full name then use that query

check what came in this

alert(callData.caller_id);
   var callerSysId = '';
        var gr = new GlideRecord("sys_user");
        gr.addQuery("name", callData.caller_id);
        gr.query();
        if (gr.next()) {
            callerSysId = gr.getUniqueValue();
        }

I believe I have provided enough guidance on this and you can enhance it further.

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

user is entering full name only, in alert as well full name is coming

suresh101_0-1740988963519.png