Does anyone have a bash script which will use the ...
# sdf
k
Does anyone have a bash script which will use the suitecloud object:list to get a list of objects in a destination account and use this list to compare to the list of objects contained in the SDF Project to determine two things. 1. Are there any objects in the SDF Project not in the list of objects in the destination account. 2. Are there any objects in the SDF Project which are comparatively different with the same object in the destination account. Then use this to rewrite the object path list in the deploy.xml file?
e
I wrote this python script to do what you're trying to do a while back. What I do is create a branch of my of my SDF project, run this script to pull in differences and then merge the changes into my main branch. You'll probably want to update the supported_types section to specify the object types and prefixes you want to import. For example, we don't store SDF objects from 3rd parties in our repo.
Copy code
import subprocess
import re
import sys
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--authid",help="Specify the NetSuite Auth ID to use")
args = parser.parse_args()

#
# Specify combination of type and scriptid prefix to import. All others will be ignored.
# Regex is supported for both type and scriptid prefix
#
supported_types = [
    {"type": "^(clientscript|usereventscript|scheduledscript|mapreducescript|suitelet|restlet|customglplugin|portlet|workflowactionscript)$", "prefix": "^customscript"},
    {"type": "customlist", "prefix": "^customlist"},
    {"type": "customrecordtype", "prefix": "^customrecord"},
    {"type": "customsegment", "prefix": "^(customrecord_cseg|cseg)"},
    {"type": "customtransactiontype", "prefix": "^(custompurchase|customtransaction)"},
    {"type": "entitycustomfield", "prefix": "^custentity"},
    {"type": "itemcustomfield", "prefix": "^custitem"},
    {"type": "othercustomfield", "prefix": "^custrecord"},
    {"type": "role", "prefix": "^customrole_rs"},
    {"type": "transactionbodycustomfield", "prefix": "^custbody"},
    {"type": "transactioncolumncustomfield", "prefix": "^custcol"},
    {"type": "workflow", "prefix": "^customworkflo_"},
]

##############


#
# Get list of objects from NetSuite account
#
print("Retrieving object list from NetSuite...")
object_results = subprocess.run([f"sdfcli listobjects -authid {args.authid}"], shell=True, capture_output=True, text=True)
if (object_results.stderr):
    print(f"Error while retreiving object list from NetSuite: {object_results.stderr}")
    sys.exit(1)
account_objects=object_results.stdout.splitlines()

#
# Combine all types so that we can run a single import per type
#
objects_to_import = {}
for object in account_objects:
    type, scriptid = object.split(":")
    if [element for element in supported_types if re.match(element["type"],type) and re.match(element["prefix"],scriptid)]:
        objects_to_import.setdefault(type,[])
        objects_to_import[type].append(scriptid)

#
# Run import from NetSuite account for each type of object
#
for objecttype in objects_to_import:
    scriptids = " ".join(objects_to_import[objecttype])
    cmd = f"echo YES | sdfcli importobjects -scriptid {scriptids} -type {objecttype} -destinationfolder /Objects/{objecttype} -authid  {args.authid} -p src/"
    importobject = subprocess.run([cmd], shell=True, capture_output=True, text=True)
    if (importobject.stderr == ""):
        print(f"{objecttype} imported successfully")
    else:
        print(f"ERROR: {objecttype} failed to import due to error: {importobject.stderr}")

#
# Cleanup SuiteScripts
# Remove carriage returns that NetSuite adds to each line when saving a script manually
# Unless we do this every line will look like a diff
#
cmd = f"git diff --name-only --diff-filter AM src/FileCabinet"
scriptdiffs = subprocess.run([cmd], shell=True, capture_output=True, text=True)
if (scriptdiffs.stderr == ""):
    scripts_to_update = scriptdiffs.stdout.splitlines()
    for script in scripts_to_update:
        cmd = f"sed -i -e 's/\r//g' {script}"
        cleanupscript = subprocess.run([cmd], shell=True, capture_output=True, text=True)
        if (cleanupscript.stderr != ""):
            print(f"Failed to cleanup script {script} due to error {cleanupscript.stderr}")

print("Import complete")
sys.exit(0)
🙌 1
k
Awesome! Thanks!!!!