How to get the length of the string field auto populated on another field and shown in list view without saving the form?

tyagisu
Mega Expert

Hi,

I need the list of managed document records where the length of the filename equals exactly 100 characters. So, I created a field "Length of file" on Revision table and captured the length of the file name in this field which is working fine as I used onload Client script. But I don't want to open each record and save it in order to appear on the list view.

I tried using fix script and before query business rule but none of them is working as expected.

Here is the code I used for Fix script

var gr = new GlideRecord("dms_document_revision");
var qry = 'attachment.file_nameISNOTEMPTY';
gr.addEncodedQuery(qry);
gr.query();
while (gr.next()) {
var field = gr.getDisplayValue('file_name').length;
if(field > 10)
{
  gr.setValue("u_length_of_file", field);
}
gr.updateMultiple();
}

find_real_file.png

1 ACCEPTED SOLUTION

Try this...

var gr = new GlideRecord("dms_document_revision");
gr.addEncodedQuery('attachment.file_nameISNOTEMPTY');
gr.query();
while (gr.next()) {
    var fieldLength = gr.attachment.getValue('file_name').length;
    if (fieldLength > 10) {
        gr.u_length_of_file = fieldLength;
    }
    gr.setWorkflow(false); // Do not run business rules
    gr.autoSysFields(false); // Do not update system fields
    gr.update();
}

View solution in original post

15 REPLIES 15

Another question.  Is there a reason you're excluding those with a field length less than 10?  Why not just update all of them?

No there isn't any reason. I can update all of them.

I changed the code from 10 to 5. Now we are looking for size>5 that way we have a broader scope as there is hardly any document with less than 5 size.

Also, I have noticed that when I run the script again and again the count reduces. I mean I ran it 3 times in a row and now the count is 24678 left.

Okay, it must just be taking a while then.  There's nothing wrong with the script so you'll probably just need to keep plugging away at it.  When you're confident it's working like it should please mark my response above as the correct response.  Thanks!

 

The progress worker shows it is completed every time. Anyways I don't mind running it 4-5 times again. 

Thank a lot.. đꙂ

 Appreciate it!