1

I'm trying to create a wsproxy script to create data folders in a BU for multiple content types. I'm struggling to understand how I can set the parent folder ID once I've retrieved them. I have a script that creates folders for a single content type.

 <script runat="server">
  Platform.Load("core", "1.1");
  var api = new Script.Util.WSProxy();

//retrieve the parentfolder ID
  var soapObjName = "DataFolder";
  var req = api.retrieve("DataFolder", ["ID"], {
    Property: "Name",
    SimpleOperator: "equals",
    Value: "Data Extensions"
  }
  );

//set the parentFolderID variable with the results
  var parentFolderId = req.Results[0].ID;

/*jSON for each folder to be created which reference the parentFolderID
If editing the names here any subfolders created will also need to be updated
in Data Folders Level 2 Create.js */
  var contentJSON = [{
    Name: "0. Base Model",
    Description: "Used to store the Base Model DEs",
    ParentFolder: {
      ID: parentFolderId,
      IDSpecified: true
    },
    IsActive: true,
    IsEditable: true,
    AllowChildren: true,
    ContentType: "dataextension"
  }

I know that I can create complex filters to retrieve multiple parent folder IDs. Here's the payload response I get when using postman and a complex filter for 2 content types:

 <RetrieveResponseMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
        <OverallStatus>OK</OverallStatus>
        <RequestID>837844e4-f6f5-4035-a9f2-0093445f623f</RequestID>
        <Results xsi:type="DataFolder">
            <PartnerKey xsi:nil="true" />
            <ID>1112</ID>
            <ObjectID xsi:nil="true" />
        </Results>
        <Results xsi:type="DataFolder">
            <PartnerKey xsi:nil="true" />
            <ID>1116</ID>
            <ObjectID xsi:nil="true" />
        </Results>
    </RetrieveResponseMsg>

How can I update this line:

var parentFolderId = req.Results[0].ID;

to be the relevant parenFolderId when I'm returning multiple?

2
  • I am not sure I fully understand your ask. Are you just looking for a way to iterate through each result? Because in that case you just need an iterator (which can be made via a FOR loop) to iterate through each object in the returned array. But I believe your ask is more complicated than that. I just honestly am not getting it. Commented Sep 12, 2022 at 14:55
  • Thanks for getting back to me. I'm trying to create a standard Data folder structure across the content types (DEs, Automations, Journeys etc), and use the script across tenants. I'm able to retrieve the parent folder IDs for each content type in the same response, but I'm unsure how I can then set the Parent Folder ID for each sub folder, as when I create the subfolder I need to specify the relevant Content Type Parent Folder ID. Commented Sep 12, 2022 at 15:23

1 Answer 1

0

I solved this by doing separate retrieve calls. I'm sure there's a more elegant way but it works.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .