• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Visual Status Dependant on Field Value being "At Least" as Expected

New Here ,
Nov 15, 2018 Nov 15, 2018

Copy link to clipboard

Copied

Hi All

I while ago I posed a question on this forum asking if anyone knew how to write a script that would have a 'Result' field show "Awaiting Input", "MATCH", or "MISMATCH", depending on whether the value entered into a in a 'Reported' field matched exactly the valued in an 'Expected' field.

The original post is here; Script for Dependant Visual Status  - I had some fantastic help from George_Johnson and try67, to whom I owe a great deal of gratitude - may thanks once again!

I now have a need for a script that will do a very similar thing, but I need the visual status of my 'Result' field to show as "Awaiting Input", "Pass" or "Fail", depending on whether the value entered into the 'Reported' field is at least the value of what is in the 'Expected' field, rather than needing to be an exact match.

So, I have a read-only field called 'Expected-Sector-Count'. The expected value is "9,514,260"

I need the 'Result' field to show as "Pass" if the value entered into the 'Reported-Sector-Count' field is equal to, or greater than, 9,514,260

If the value entered into the 'Reported-Sector-Count' field is less than 9,514,260 then I need the 'Result' field to show as "Fail"

If the 'Reported-Sector-Count' field is blank, then the 'Result' field should show as "Awaiting Input".

Is it at all possible to modify the script below to achieve this? I'm assuming I would need to remove the comma separators from the values, but hopefully I can get them to show if I format the respective fields as 'Number' ?

I should mention this is not for profit and I would be extremely grateful if anyone could help! Many thanks in advance.

// Custom calculation JavaScript for text field

(function () {

    // Get the field value, as a string, converted to uppercase

    var sHash = getField("Acquired_Hash").valueAsString.toUpperCase();

    if (sHash) {  // Not blank

        if (sHash === this.getField("Expected Hash").valueAsString.toUpperCase()) {

            event.value = "Match";

            event.target.textColor = color.green;

        } else {

            event.value = "MIS-MATCH";

            event.target.textColor = color.red;

        }

    } else {  // Input is blank

        event.value = "Awaiting Input";

        event.target.textColor = color.black;

    }

})();

TOPICS
Acrobat SDK and JavaScript

Views

432

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Nov 15, 2018 Nov 15, 2018

You can see if this helps get you close...

(function() {

    var sectorCount = getField("Expected-Sector-Count").value;

    var expectedValue = 9514260;

    var theOutputPhrase;

    if (sectorCount >= expectedValue) {

        theOutputPhrase = "Pass";

        this.getField("Results Field").value = theOutputPhrase;

    } else if (sectorCount < expectedValue) {

        theOutputPhrase = "Fail";

        this.getField("Results Field").value = theOutputPhrase;

    } else {

        theOutputPhrase = "Awaiting Inp

...

Votes

Translate

Translate
Engaged ,
Nov 15, 2018 Nov 15, 2018

Copy link to clipboard

Copied

You can see if this helps get you close...

(function() {

    var sectorCount = getField("Expected-Sector-Count").value;

    var expectedValue = 9514260;

    var theOutputPhrase;

    if (sectorCount >= expectedValue) {

        theOutputPhrase = "Pass";

        this.getField("Results Field").value = theOutputPhrase;

    } else if (sectorCount < expectedValue) {

        theOutputPhrase = "Fail";

        this.getField("Results Field").value = theOutputPhrase;

    } else {

        theOutputPhrase = "Awaiting Input";

        this.getField("Results Field").value = theOutputPhrase;

    }

})();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 21, 2018 Nov 21, 2018

Copy link to clipboard

Copied

subieguy2, many thanks for your response! Apologies for the delayed reply.

Your script was 95% perfect, thank you! The only slight issue is that the Result field shows 'Fail' rather than 'Awaiting Input' if the 'Reported Sector Count' field is blank; presumably this is because the script sees a blank entry as '0' and therefore less than 9514260, hence why it shows as Fail.

Is there any way to modify the script to correct this?

Many thanks in advance

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 17, 2018 Dec 17, 2018

Copy link to clipboard

Copied

LATEST

Sorry for the WAY long delay... Not sure if you got this sorted out or not but you should be able to just update your else if statement. Like this...

(function() { 

    var sectorCount = getField("Expected-Sector-Count").value; 

    var expectedValue = 9514260; 

    var theOutputPhrase; 

    if (sectorCount >= expectedValue) { 

        theOutputPhrase = "Pass"; 

        this.getField("Results Field").value = theOutputPhrase; 

    } else if (sectorCount < expectedValue && sectorCount != "") { 

        theOutputPhrase = "Fail"; 

        this.getField("Results Field").value = theOutputPhrase; 

    } else { 

        theOutputPhrase = "Awaiting Input"; 

        this.getField("Results Field").value = theOutputPhrase; 

    } 

})();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines