Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Help on portal related issue.

Sahil Chaudhary
Tera Contributor

I have created the portal with required pages and widgets (can be found in attachment). However, I am struggling with the submit function and the record is not getting inserted into the customer case table. When I click on the submit button, there is no response.

Attaching Files and screenshot

 

widget 1: Case Submission Form

 

HTML Code:

<div class="panel panel-default case-submission-form">
<div class="panel-heading"><h4>Submit a Case</h4></div>
<div class="panel-body">
<form ng-submit="c.submitCase()" novalidate>

<div class="form-group" style="margin-bottom: 20px;">
<label>Customer Name</label>
<input class="form-control" type="text" ng-model="c.form.customerName" placeholder="Your name" required>
</div>

<div class="form-group" style="margin-bottom: 20px;">
<label>Issue Description</label>
<textarea class="form-control" ng-model="c.form.issueDescription" rows="4" placeholder="Describe your issue" required></textarea>
</div>

<button class="btn btn-primary" type="submit">Submit Case</button>
</form>
</div>
</div>

 

Server Script:

(function() {

    // Handle form submission
    if (input && input.action === 'createCase') {
        try {
            var caseData = input.case || {};
            var gr = new GlideRecord('x_880053_csm_porta_customer_case');
            gr.initialize();

            gr.customer_name = caseData.customerName || gs.getUserName();
            gr.issue_description = caseData.issueDescription || '';
            gr.opened_by = gs.getUserID();

            var sysId = gr.insert();
            data.result = {
                sys_id: sysId.toString(),
                number: gr.getValue('number')
            };
        } catch (error) {
            gs.error('Error creating case: ' + error.message);
            data.error = 'Failed to create case. Please try again later.';
        }
    }
})();
 
Client Script:
api.controller = function() {
    var c = this;


    // Submit case
    c.submitCase = function() {
        try {
            if (!c.form.customerName || !c.form.issueDescription) {
                spUtil.addErrorMessage('Please fill in all required fields.');
                return;
            }

            c.server.update({
                action: 'createCase',
                case: c.form
            }).then(function(response) {
                if (response.data && response.data.result) {
                    spUtil.addInfoMessage('Case submitted: ' + response.data.result.number);
                    c.emit('cases:created', response.data.result);
                } else {
                    spUtil.addErrorMessage('Failed to submit case.');
                }
            }, function() {
                spUtil.addErrorMessage('Server error while creating case.');
            });
        } catch (error) {
            spUtil.addErrorMessage('An unexpected error occurred: ' + error.message);
        }
    };
};
 
Link:
function link(scope, element) {
    function focusFirstField() {
        var inputEl = element.find('input')[0];
        if (inputEl) inputEl.focus();
    }
    setTimeout(focusFirstField, 0);

    scope.$on('cases:created', function() {
        setTimeout(focusFirstField, 0);
    });
}
 

1 ACCEPTED SOLUTION

Raghav Sharma24
Giga Patron

Hi Sahil,

You are not invoking any function from your button, on high level your code is correct, try below

<button class="btn btn-primary" type="submit" ng-click="c.submitCase()">Submit Case</button>

 

Also try putting some logs in server side after input so that you know where your code is failing.

Try adding some alerts in client script.

 

Also check your widget and table application scope is same.

 

View solution in original post

1 REPLY 1

Raghav Sharma24
Giga Patron

Hi Sahil,

You are not invoking any function from your button, on high level your code is correct, try below

<button class="btn btn-primary" type="submit" ng-click="c.submitCase()">Submit Case</button>

 

Also try putting some logs in server side after input so that you know where your code is failing.

Try adding some alerts in client script.

 

Also check your widget and table application scope is same.