Solved

Client Script-passing value to different table

  • 8 October 2021
  • 5 replies
  • 391 views

Userlevel 3
Badge +3

Hi,

I have a requirement for passing data from one table to another table by clicking on button. 

Example: In service table there are multiple row records where user_def1 is equal to 1. Once I create request I need to pass that request id to service table where user_def1 is equal to 1.I am not able to use setDBvalue since this requirement is for web client.

Please suggest feasible way to do this requirement.

 

Regards,

Ramya

 

icon

Best answer by Atheeq Maharoof 19 October 2021, 11:51

View original

5 replies

Userlevel 5
Badge +12

Hi @RamyaR ,

In order to achieve this requirement, you can create a custom sql script to get all the service table records where user_def1 is equal to 1. 

SELECT * FROM service WHERE  user_def1 = ‘1’

Then you can create a for loop for the service records and perform a createInsertUpdate for each rows setting the request_id (the id can be fetched using the getControlValue method). I havent tried this functionality but according to the web client custom client scripts you can use the createInsertUpdate function to  update a record. 

 

CreateInsertUpdate request 

Further you can refer the baseline client scripts which uses the above function. For an example -ASSIGNLOOKUPWEB_ADD_RESOURCE_BUTTON

Hope this answer helps

Best Regards,
Atheeq

Userlevel 3
Badge +3

@Atheeq Maharoof thanks for the response,

I have done this requirement with below client script, It’s working fine but I am getting popup error like can’t properties. Could you please help me to identify missing thing in code.

var req= getControlvalue(‘request’, ’request_id’);

var val = getDBValue(“IMPACTED”); // client script sql to get data from other table

if(isNullorEmptyString(val)!= true)

{

for(var rowIndex = 0;rowIndex <=size(val);++rowIndex){

var vals={};

vals.task_id =val[rowindex][“task_id”];

vals.user_def2 =’req’;

updateRow(‘impacted_req’,vals);

}}

Client script SQL:

IMPACTED: select *from impacted_req where user_def1= ‘1’

Error :

 

Regards,

Ramya

 

 

Userlevel 5
Badge +12

Hi @RamyaR ,

The error states that the task_id cannot be read from undefined. When checking the  place where it has been used, the “rowindex” variable in the line “vals.task_id =val[rowindex][“task_id”];" has not been declared in the above code due to this you are getting an undefined reference where it cannot find the task_id. I think you have mistaken the rowIndex variable as rowindex (the variable names are case sensitive). Changing the rowindex  to rowIndex will fix the issue.

Hope this answer helps.

Best Regards,
Atheeq

Userlevel 3
Badge +3

@Atheeq Maharoof 

I tried same by changing variable but same error I am getting.

 

Regards,

Ramya

Userlevel 5
Badge +12

Hi @RamyaR,

Was able to recreate the issue you are facing. 

 

Error

 Following are the points you should consider. First make sure whether the task_id is a valid column in the table and the IMPACTED sql script should have the quotation mark properly for 1. When I copy pasted your exact IMPACTED sql script it did not work properly. Initially execute the script in the DB query tool and then copy paste that script to the custom sql script. Since you are fetching multiple rows, use getDBValues function.  

 

Impacted - Custom SQL script
Client Script -  getDBValue
Alert displayed with the request_id


Hope this answer helps

Best Regards,
Atheeq

Reply