简体   繁体   中英

Javascript only works with an alert

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;
    }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM