Update an empty field in custom table

Nadeem Basha
Tera Contributor

Hi Team ,

I would like to know if there is any script that can be written in the background script /fix script to fix the problem.

We have a custom table called "u_support" with many records in it and if i put a condition like "Year" is "2024" in filter ,it pulls up all the 2024 records but the problem is in many records there is one field called "Last Year " which is referring to the same table "u_support" is empty .

Basically "Last Year" reference field should have a record of the previous year which is already available in the "u_support" table.

Inorder to map the previous year records in the empty "Last year" field ,i would like to have a script written in the background .

can anyone help on this pls?

 

Thanks 

 

 

 

3 REPLIES 3

Mark Manders
Mega Patron

This sounds like a really weird custom table. How many records are you talking about? Can't you just select all records you need to update and do an 'update all'? 

 

If it's too many, you can use something like

var record = new GlideRecord('u_support');
record.addEncodedQuery('your_encoded_query_for_selected_records');
record.query();
while(record.next()){
record.setValue('u_last_year','sys_id of value'); // set correct field and correct sys_id, since you mention it's a reference field
record.update();
}

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi Mark,

Thank you for the response .

Let me pls explain a bit more on this issue for your better understanding.

In the custom table if i put some condition like year is 2024 ,type is sales ,etc, etc , it pulls the respective records .

Here the problem is , there is a field  called "Last Year " which is a reference field pointing towards the same custom table and it displays  empty instead it should have been mapped with the records that belongs to the year 2023  .

For some reason it did not happen properly and so i am trying to map the correct record with all the empty reference field by running a script in backend.

For example : if there are 250 records for the year 2024 ,in which  the field "Last year" displays empty  which means there are like 250 records available in the same custom table for the year 2023 and those records should be have been  mapped .

With the above script u mentioned i can only map a single record to all the empty field records but my requirement is of mapping each empty record (2024) with its corresponding last year record (2023).

Any input on this would be of great help.

If any clarification needed ,pls revert.

 

Thanks

What do you mean? The 'while' condition in the script makes sure you update all of the records.

I am completely lost on your explanation about 250 records for 2024 that don't have last year filled and should be mapped to 2023? 

Please be advised that we have no access to your instance, so we need to understand you from your explanation.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark