SP Widget input action = 'cancelRecord' and clean date field with setValue

Elton2
Tera Contributor

Hi everyone, good afternoon!

I'm stuck on a task, could someone help me or suggest something? 

 

User when clicking on the "Cancel" button or even invoking a

"c.cancel()"

 

This function will have an action = "cancel" that will be passed on the Server (input.action = 'cancel')

will make a Glide Record on the table and set the field "emission_date" without information.

That is, when the user cancels the registration, he has to clear the "emission_date" field.

Note: I tried using UI Policy and BR, but it is necessary via script.

 

HTML:

<button ng=click="c.cancelRecord()">Cancel</button>

 

Client Script:
c.cancelRecord = function(){

var input = {
action: 'cancelNewRegister'
};

c.server.get(input).then(function(resp){

})

}

}

 

Server Script:
if (input && input.action == "cancelNewRegister"){

var grCancelRecords = new GlideRecord("doc_all_records")
grCancelRecords.addEncodedQuery('state=300^ORDERBYnumber')
grCancelRecords.query();

while(grCancelRecords.next()){
grCancelRecords.setValue('emission_date', "")
grCancelRecords.update();

}
}

 

Tks for your support.

 

4 REPLIES 4

Markus Kraus
Kilo Sage

Can you explain your problem in more details? I do not really see what the issue is / what you are trying to achieve.

 

Some general comments:

1.) If you need simple client side UI Actions in the Portal, consider using this scoped app which enables exactly this feature in the portal:
[Show Case] The (Service) Portal Experience App: Client Side UI Actions on OOTB Form and Data Table
2.) The Server Script can be improved using the "updateMultiple" method of the GlideRecord Object:

 

var grCancelRecords = new GlideRecord("doc_all_records")
grCancelRecords.addEncodedQuery('state=300^ORDERBYnumber')
grCancelRecords.setValue('emission_date', "")
grCancelRecords.updateMultiple();

 

 

Hi @Markus Kraus 

When the user clicks the cancel button, the registration needs to be canceled and for that it is necessary that there is an action: 'cancelNewRegister' (Client Script) and that it is passed in the input in the Server Script, I tried to make another code, but it's not working:

 

HTML:

<button ng-click="c.cancelRecord()">Cancel</button>

 

CLIENT SCRIPT:

c.cancelRecord = function(){
var input = {};
input.action = "cancelRecord"
c.server.get(input);
}

 

SERVER SCRIPT:

var grCancelRecords = new GlideRecord("x_doc_all_records")

if(input && input.action){
if(input.action == "cancelRecord"){
grCancelRecords.setValue('emission_date', ' '); //when canceled the value of this field will be removed/erase/blank
}

if(grCancelRecords.update()){
gs.addInfoMessage("Your record has been canceled");
}else {

gs.addErrorMessage(''Update failed")

}
}

 

Briefly: User needs to Cancel the registration and when canceling the registration it needs to be "erase", due to the fact I'm using setValue('emission_date', ' ');

 

Marco0o1
Tera Sage

Hi @Elton2 ,

You script in the server script you are query all the records that has the criteria of "state=300^ORDERBYnumber" is this correct? you dont look for a specific record for the user is logged or use any sys_id? the "doc_all_records" is a custom table? And if you want to check some dubigging in your code you can add a info message if you really go into the record like this in the server:

 

if (input && input.action == "cancelNewRegister"){

var grCancelRecords = new GlideRecord("doc_all_records")
grCancelRecords.addEncodedQuery('state=300^ORDERBYnumber')
grCancelRecords.query();

while(grCancelRecords.next()){
gs.addInfoMessage(grCancelRecords.getValue('emission_date'); // If you want to display if you really are into the widget and the value you want to change.
grCancelRecords.setValue('emission_date', "")
grCancelRecords.update();

}
}

Elton2
Tera Contributor

Hi @Marco0o1

I thought about this query, because "300" is the status that precedes the Cancellation, that is, the status 300 is New Registration, after that the user will be able to perform the Cancellation, but I will not use this query anymore. 

I even tried another code (below), but I don't know if it's right, do you have any suggestions?

HTML:

<button ng-click="c.cancelRecord()">Cancel</button>

 

CLIENT SCRIPT:

c.cancelRecord = function(){
var input = {};
input.action = "cancelRecord"
c.server.get(input);
}

 

SERVER SCRIPT:

var grCancelRecords = new GlideRecord("x_doc_all_records")

if(input && input.action){
if(input.action == "cancelRecord"){
grCancelRecords.setValue('emission_date', ' '); //when canceled the value of this field will be removed/erase/blank
}

if(grCancelRecords.update()){
gs.addInfoMessage("Your record has been canceled");
}else {

gs.addErrorMessage(''Update failed")

}
}

 

Briefly: User needs to Cancel the registration and when canceling the registration it needs to be "erase", due to the fact I'm using setValue('emission_date', ' ');

 

Tks again!