1

I wrote some Javascript that loops through xml nodes using the FormAPI for Teamsite and removes a value from one of the nodes. The removeID function only works properly when the alert is in it. I've tried separating actions into different functions and putting a setTimeout() on them but nothing works. The script only executes when the page is being saved and closed so the page has definitely already been loaded. Anyone have any other ideas?

This works:

   function removeID(xPath) {

        if(xPath.getChildByName('path') != undefined && xPath.getChildByName('id') != undefined){
          if(xPath.getChildByName('path').getValue() == "" && xPath.getChildByName('id').getValue() != ""){

              xPath.getChildByName('id').setValue('');

            alert("replaced ");
          }
        }

        return true;
    }

This does not work (no alert):

      function removeID(xPath) {

        if(xPath.getChildByName('path') != undefined && xPath.getChildByName('id') != undefined){
          if(xPath.getChildByName('path').getValue() == "" && xPath.getChildByName('id').getValue() != ""){

              xPath.getChildByName('id').setValue('');

          }
        }

        return true;
    }
  • Can you provide a [SSCCE](http://sscce.org/)? Also, on a side note, variables in loops (your `i`s) are not automatically local (i.e. you are declaring implicit globals there). – Ingo Bürk Nov 05 '13 at 17:54
  • Sure, I updated the question and presentation to be a little more clear. Hope that helps. – user2957072 Nov 05 '13 at 19:17
  • The "SCC" in the middle stands for "self-contained, compilable", so it would be helpful to have actually executable code to reproduce the problem. Ideally, a little [jsfiddle](http://www.jsfiddle.com). A description of what "does not work" actually means (expected output, actual output) would also be helpful, though a fiddle would suffice. Sorry for all the trouble, but step #1 to any problem is reproducing it :) – Ingo Bürk Nov 05 '13 at 19:21
  • go check formapi documentation – Susheel Singh Apr 22 '14 at 11:30

1 Answers1

0

FormAPI is not Javascript, but an HP specific framework based on Javascript. Your code is trying to manipulate the XML (also called DCR in TeamSite world) which is a bad practice and can lead to bad results.

Instead you will need to IWItem object, specifically perhaps IWItem.deleteInstance() method to achieve the result.

You should also try to get some training from a vendor like autowoven so you don't "hack" the system.