amtrack / sfdx-browserforce-plugin

sfdx plugin for browser automation
MIT License
109 stars 38 forks source link

Error adding picklist value #479

Closed Raptor399 closed 2 years ago

Raptor399 commented 2 years ago

I am trying to add a picklist value and get the following error message:

ERROR running browserforce:apply:  The "url" argument must be of type string. Received undefined

I don't understand which "url" argument the error message is talking about, or what I can do to prevent the problem.

To reproduce, use the following files:

sfdx-project.json

{
  "namespace": "",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": "52.0"
}

config/project-scratch-def.json

{
  "country": "US",
  "edition": "Developer",
  "settings": {
    "lightningExperienceSettings": {
      "enableS1DesktopEnabled": true
    }
  },
  "orgName": "Test",
  "adminEmail": "test@test.com"
}

config/project-scratch-browserforce.json

{
    "$schema": "https://raw.githubusercontent.com/amtrack/sfdx-browserforce-plugin/master/src/plugins/schema.json",
    "settings": {
        "security": {
            "loginAccessPolicies": {
                "administratorsCanLogInAsAnyUser": true
            }
        },
        "picklists": {
            "picklistValues": [{
                    "metadataType": "StandardValueSet",
                    "metadataFullName": "ForecastCategoryName",
                    "value": "Most Likely",
                    "newValue": "Most Likely",
                    "active": true
                }
            ]
        }
    }
}

With these files, run the following commands:

$ sfdx force:org:create -s -a scratch -f config/project-scratch-def.json --wait 10
(node:11429) [DEP0147] DeprecationWarning: In future versions of Node.js, fs.rmdir(path, { recursive: true }) will be removed. Use fs.rm(path, { recursive: true }) instead
(Use `node --trace-deprecation ...` to show where the warning was created)
Successfully created scratch org: 00D1j000000EP2uECG, username: test-p0krdduvd2tc@example.com
$ sfdx force:config:set defaultusername=scratch
=== Set Config
Name             Value    Success
───────────────  ───────  ───────
defaultusername  scratch  true
$ sfdx browserforce:apply -f config/project-scratch-browserforce.json --targetusername scratch
logging in... done
Applying definition file config/project-scratch-browserforce.json to org test-p0krdduvd2tc@example.com
[Security] retrieving state... done
[Security] no action necessary
[Picklists] retrieving state... failed
ERROR running browserforce:apply:  The "url" argument must be of type string. Received undefined
logging out... done
$ 

Notice how the security action seems to run fine, whereas the picklist action doesn't.

github-actions[bot] commented 2 years ago

:tada: This issue has been resolved in version 2.8.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

amtrack commented 2 years ago

@Raptor399 Thanks for you report!

I wasn't aware of the StandardValueSet ForecastCategoryName and so there was no mapping entry yet. I've now added one in the latest release.

Please note that you'll have to provide statusCategory (instead of value):

        {
          "metadataType": "StandardValueSet",
          "metadataFullName": "ForecastCategoryName",
          "newValue": "Most Likely",
          "statusCategory": "Most Likely",
          "active": true
        }

P.S.: Unfortunately it's difficult to keep track of available StandardValueSets. If you know some other resource/API to list all available StandardValueSets, please let me know. I'm only aware of https://developer.salesforce.com/docs/atlas.en-us.234.0.api_meta.meta/api_meta/standardvalueset_names.htm where ForecastCategoryName is not listed.

Raptor399 commented 2 years ago

Thank you for the update and the correction, @amtrack !

I'm getting an error when trying to apply the modified project-scratch-browserforce.json to a new test org, though? This is what I get:

$ sfdx plugins       
sfdx-browserforce-plugin 2.8.0
$ sfdx browserforce:apply -f config/project-scratch-browserforce.json --targetusername scratch

logging in... done
Applying definition file config/project-scratch-browserforce.json to org test-cmuq29hktfni@example.com
[Security] retrieving state... done
[Security] no action necessary
[Picklists] retrieving state... done
[Picklists] changing 'picklistValues' to '[{"metadataType":"StandardValueSet","metadataFullName":"ForecastCategoryName","newValue":"Most Likely","statusCategory":"Most Likely","active":true}]'... failed
ERROR running browserforce:apply:  waiting for XPath `//tr[td[2][text() = "undefined"]]//td[1]//a[contains(@href, "/setup/ui/picklist_masteractivate.jsp")]` failed: timeout 30000ms exceeded
logging out... done
amtrack commented 2 years ago

@Raptor399 OK, I'm able to reproduce this. Will look into it.

amtrack commented 2 years ago

@Raptor399 Sorry for the wrong config I provided last time! The active property should be omitted. When adding a new picklist palue, it is set active by default. So there is no need to provide the active property. The code actually interprets a given active property as instruction to enable/disable an existing picklist value.

I've tried the following config, and it seems to work now:

config/project-scratch-browserforce.json:

{
  "$schema": "https://raw.githubusercontent.com/amtrack/sfdx-browserforce-plugin/master/src/plugins/schema.json",
  "settings": {
    "security": {
      "loginAccessPolicies": {
        "administratorsCanLogInAsAnyUser": true
      }
    },
    "picklists": {
      "picklistValues": [
        {
          "metadataType": "StandardValueSet",
          "metadataFullName": "ForecastCategoryName",
          "newValue": "Most Likely",
          "statusCategory": "Most Likely"
        }
      ]
    }
  }
}
$ sfdx browserforce:apply -f config/project-scratch-browserforce.json
logging in... done
Applying definition file config/project-scratch-browserforce.json to org test-3akzhbwfgno5@example.com
[Security] retrieving state... done
[Security] no action necessary
[Picklists] retrieving state... done
[Picklists] changing 'picklistValues' to '[{"metadataType":"StandardValueSet","metadataFullName":"ForecastCategoryName","statusCategory":"Most Likely","newValue":"Most Likely"}]'... done
logging out... done

$ sfdx browserforce:apply -f config/project-scratch-browserforce.json
logging in... done
Applying definition file config/project-scratch-browserforce.json to org test-3akzhbwfgno5@example.com
[Security] retrieving state... done
[Security] changing 'loginAccessPolicies' to '{"administratorsCanLogInAsAnyUser":true}'... done
[Picklists] retrieving state... done
[Picklists] no action necessary
logging out... done
Raptor399 commented 2 years ago

Excellent! Can confirm this works on my end as well. Thank you for investigating!