What I am trying to do is to automatize a process of passing results from one SFDX command to another SFDX command and I struggle to implement that.

My source command is

sfdx force:package:installed:list -u sourceOrg

I could even run JSON variant of it like

sfdx force:package:installed:list -u sourceOrg --json

so that it returns me a json data which I can then assign to a javascript variable and select SubscriberPackageVersionId of these results

var a = {
  "status": 0,
  "result": [
      "Id": "0A3E00000002ricKAA",
      "SubscriberPackageId": "033300000004PVbAAM",
      "SubscriberPackageName": "License Management App",
      "SubscriberPackageNamespace": "sfLma",
      "SubscriberPackageVersionId": "04t30000001DWL0AAO",
      "SubscriberPackageVersionName": "1.20",
      "SubscriberPackageVersionNumber": ""
      "Id": "0A3E00000002rigKAA",
      "SubscriberPackageId": "033A0000000PB5YIAW",
      "SubscriberPackageName": "DocuSign For Salesforce",
      "SubscriberPackageNamespace": "dsfs",
      "SubscriberPackageVersionId": "04tA0000000SEKIIA4",
      "SubscriberPackageVersionName": "6.6.4",
      "SubscriberPackageVersionNumber": ""

Then using results of a.result.map(x=>x.SubscriberPackageVersionId) I could pass it to the destination command like following

FOR %%P IN (04t30000001DWL0AAO,04tA0000000SEKIIA4) DO sfdx force:package:install -i %%P -u %1 -r -w 1

I am struggling to automatize this but not sure how this can be automated.

Should I write some custom SFDX plugin? I have seen a question about how one can execute an existing SFDX command inside a SFDX plugin but there was no definite answer, so, looks like it is impossible or I don't understand how to implement that.

Should I use jq? I am not able to install jq on windows and not able to run any commands from jq. Even if I had jq installed, I would still struggle how to use it for my case.


Figured out how to pass the result of the first command into jq on windows

sfdx force:package:installed:list -u sourceOrg --json | ~/Downloads/jq.exe '.result[].SubscriberPackageVersionId'

Found a bash script which would run the conversion I was looking for

for a in $(sfdx force:package:installed:list -u sourceOrg --json | ~/Downloads/jq.exe -r '.result[].SubscriberPackageVersionId'); do 
echo $a
sfdx force:package:install -p $a -u destOrg -r -w 1000; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.