Pass Input Value to server side on a widget

Vinicius Luz1
Tera Expert

Hello,

 

I have this html input here:

    <div id="section-reprogramacao" ng-if="data.isProgFeriasCase">
     	<div>
            <label for="changeVacationInput"> Data inicial para reprogramação de férias </label><br>
    		<input id = "changeVacationInput"  type="textarea" href="javascript&colon;void(0)" > 
            <button class="btn btn-primary" ng-click="changeVacationDay()"> Reprogramar Férias </button>
    	</div>  
   </div>

This is what I have in the client controller:

    $scope.changeVacationDay = function() {
		
        $scope.data.action = "changeVacationDay";
        $scope.server.update();
    };

and server script:

    if (input && input.action == 'changeVacationDay') {
		var value = '24-04-1995'
        var grCaseTR = gr.sysapproval.getRefRecord();
        grCaseTR.u_ferias_reprogramadas_por_gestor = true;
		grCaseTR.u_data_inicial_ferias = value;
        if (grCaseTR.update()) {
            gs.addInfoMessage("Férias reprogramadas com sucesso");
        } else {
            gs.addInfoMessage("Erro ao reprogramar férias");
        }
        return;
    }

 

This is actually working good, the only missing piece would be the value on the input that Im not being able to capture. You can note that Im using a hardcoded value as date there ("24-04-1995").

 

What I need this button to do is to call a function that will get the input on the textarea and pass it to the server side so I can update the record with the populate value.

 

Any help would be very much appreciated. Thanks,
Vini

3 REPLIES 3

Samaksh Wani
Giga Sage
Giga Sage

Hello @Vinicius Luz1 

 

Plz find the below link similar to your query. Refer the code and execute.

 

https://www.servicenow.com/community/developer-forum/get-input-to-pass-into-server-script-for-a-serv...

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

Vanderlei
Mega Sage

 

 

Hi @Vinicius Luz1 , try this

 

 

    <div id="section-reprogramacao" ng-if="data.isProgFeriasCase">
     	<div>
            <label for="changeVacationInput"> Data inicial para reprogramação de férias </label><br>
    		<input type="text" class="form-control" uib-datepicker-popup ng-model="c.vacationDay" datepicker-options="c.dateOptions" ng-required="true" close-text="Close" />
            <button class="btn btn-primary" ng-click="changeVacationDay()"> Reprogramar Férias </button>
    	</div>  
   </div>

 

 

 

Client:

 

 

    $scope.changeVacationDay = function() {
		
        $scope.data.action = "changeVacationDay";
$scope.data.vacationDay = c.vacationDay
        $scope.server.update();
    };

 

 

Server:

    if (input && input.action == 'changeVacationDay') {
		var value = input.vacationDay
        var grCaseTR = gr.sysapproval.getRefRecord();
        grCaseTR.u_ferias_reprogramadas_por_gestor = true;
		grCaseTR.u_data_inicial_ferias = value;
        if (grCaseTR.update()) {
            gs.addInfoMessage("Férias reprogramadas com sucesso");
        } else {
            gs.addInfoMessage("Erro ao reprogramar férias");
        }
        return;
    }



If my answer helped you, please mark my answer as helpful.

 

Vanderlei Catione Junior | LinkedIn

Senior ServicePortal Developer / TechLead at The Cloud People

 

Vi que você fala português, caso queira, pode me dar um toque