Create Delete action button in Service Portal for deleting record

mahfooz1
Tera Contributor

Create Delete action button in Service Portal for deleting record

1 ACCEPTED SOLUTION

mr18
Tera Guru
Tera Guru

Create a widget as below

HTML:

<div class="panel b ng-scope">
    <div ng-if="data.states != 4"> <!--4 is the value of cancel -->
        <div class="panel-heading bg-primary panel-la-jolla-default">Actions</div>
        <div class="panel-body" >
          <button type="button" class="btn btn-danger btn-block" ng-click="c.uiAction('delete')">Delete</button>
        </div>
      </div>
</div>


CSS:

.header {
 background-color: #2b0c99 
}

 

Client Script:

function() {
 var c = this;
    c.uiAction = function(action) {

        c.data.action = action;
 if (c.data.action == 'delete') {
var ans = confirm("Are you sure, you want to delete it?");
      if (ans == true)
	update();
		else
		return false;
            }

 function update() {
            c.server.update().then(function() {
                c.data.action = undefined;
                c.data.result = "completed";
            });
            window.setTimeout(restartscreen, 2000);

            function restartscreen() {
                location.reload(true);
            }
        }
 };
}

 

Server Script:

(function() {
    var gr = $sp.getRecord();

    // Get table & sys_id
    data.table = input.table || $sp.getParameter("table");
    data.sys_id = input.sys_id || $sp.getParameter("sys_id");

    data.canRead = gr.canRead();
    if (!data.canRead)
        return;

    data.canWrite = gr.canWrite();
    if (!data.canWrite)
        return;

    var states = "";
    var b = $sp.getField(gr, 'state');
    if (b != null)
        states = b.value;
	
	var stages = "";
	var t = $sp.getField(gr, 'stage');
	if(t != null)
		stages = t.value;
	
	var ReqCancel = "";
	var c = $sp.getField(gr, 'u_asked_cancellation');
	if(c != null)
	ReqCancel = c.value;	


    // Valid GlideRecord
    gr = new GlideRecord(data.table);
    if (!gr.isValid())
        return;

    // Valid sys_id
    if (!gr.get(data.sys_id))
        return;

if (input && input.action) {
        var action = input.action;
 if (action == 'delete')
gr.deleteRecord();
}

View solution in original post

6 REPLIES 6

Akshata jamdar
Mega Guru

Hi,

Set $scope.data.action to update or delete when the respective button is pressed, then on the server say if(input.action =="delete")

 

try with this,

 

 

Thanks,

Akshata

Upender Kumar
Mega Sage

Hi

 

HTML Code

<input type="button" sn-model='c.data.action' ng-click="postRequest()" class="btn btn-primary" value="Submit" ng-disabled="data.isPosting"/>

 

Client Side

$scope.postRequest= function() {
$scope.data.action='delete';

c.server.update();
}

 

Server Side

if(input){
gs.log('Server Side:'+input.action);
}

 

Thanks

 

It is not working

Hi 

Since Service Portal was primarily introduced for end users, and you're generally not giving end users delete access for records, it seems like that's not a very wide use case. If you're using the form widget in Service Portal, you could pretty easily just add a non-client side delete button to your form so that it shows in SP.