2

I'm using the extract data widget to create extract files. It writes these files to the logged in portal user's content.

I want to tag the items that were just created but I can't find anywhere in the api that lets me do that.

Example of what I want to do:

var myUrl = 'somevalue';  // I know this value at runtime, so not a problem.
var myItemId = 'someOtherValue'; // Ditto.

var thisPortal = new arcgisPortal.Portal(myurl);
thisPortal.signIn().then(function (loggedInUser) {
    loggedInUser.getItem(myItemId).then(function(theItem) {
         // I want to add a tag to the item so I know it's ok to automatically toss it a day later.
         theItem.tags[theItem.tags.length] = 'Delete in One Day';
        // I want to write the item back to the portal.
        // And I cannot find any documentation on this step!
    })
});

The guidelines for asking a good question say to "Make it clear how your question is relevant to more people than just you." I don't want to have to trust the users to clean up after themselves. I have a concern that they will clog up the disk with extract files that they will never look at again and never throw away again.

I can ask the users to mark whether the extract should be held temporarily or permanently before the extract files are created (and default to temporarily!) If I then tag the extract files accordingly, I can have an automated program run every evening and toss out the expired ones.

1

This works:

var myUrl = 'somevalue';  // I know this value at runtime, so not a problem.
var myItemId = 'someOtherValue'; // Ditto.



var thisPortal = new arcgisPortal.Portal(myurl);
thisPortal.signIn().then(function (loggedInUser) {

    var theToken = loggedInUser.credential.token;
    loggedInUser.getItem(myItemId).then(function(theItem) {
         // I want to add a tag to the item so I know it's ok to automatically toss it a day later.
         // then I want to write the item back to the portal.
         // I could not find any way to do this in the 3.20 javascript api, so I'm using the restful api.
         var tagsCsv = '';
         for (var i = 0; i < theItem.tags.length; i++) {

             tagsCsv = tagsCsv + theItem.tags[i] + ',';
         }
         tagsCsv = tagsCsv + 'Delete in One Day';

         // I could not find any documentation for the restful api to do this either, but I could observe via the

         // browser debugger what the portal did when I manually added a tag to the portal item.

         var updateUrl = '{portalUrl}sharing/rest/content/users/{userId}/items/{itemId}/update';
         updateUrl = updateUrl.replace('{portalUrl}',myUrl);
         updateUrl = updateUrl.replace('{userId}',loggedInUser.username);
         updateUrl = updateUrl.replace('{itemId}', theItem.id);
         xhr.post(updateUrl, {

            data: {

                tags: tagsCsv,
                clearEmptyFields: 'true',
                id: theItem.id,
                f: 'json',

                token: theToken

            }

         }).then(function(data) {  // officially a success

                  // inspect and take whatever action you deem fit.

             },

             function(error) {   // officially a failure

                  // inspect and take whatever action you deem fit.

             },

             function(evt) {  // status notification, works depending on the browser version.

                  // inspect and take whatever action you deem fit.

             });

    });
});

I had to transpose this by hand, hopefully it's syntactically correct. If not, post the mistakes and I'll edit it to match.

  • Haven't you tested it yet? It is OK to accept your answer if it works. – fatih_dur May 26 '17 at 9:00
  • Yes, I tested the original code. But the code is on a machine that's not connected to the internet and I can't just cut and paste it here. So I had to manually read the code on one machine and type it into this site. It's possible there is a typo that I didn't catch. – david wendelken May 27 '17 at 14:02

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.