I have call server code to see if there is a conflict. So I can popup and reject the name. Maybe a better solution. I suppose I could write a popup that asks if it should overwrite, yes or no. Anyone try any other options? Is there a way to use setName without overwrite set ?Andy
IWDCRInfo.setDCRName(myDcrName, checkStatus); . . .//---------------------------------------------------------------function checkStatus() { var status = IWDCRInfo.getStatus(); if (status == IWDCRInfo.PENDING) { //Check again in 2 sec setTimeout("checkStatus()",2000); } else if (status == IWDCRInfo.AVAILABLE) { if (!confirm("DCR Exists. Do you want to override it?")) { // Restore Original name, Set "Bad Name" Flag to check onSave // and reject, etc... } } else if (status == IWDCRInfo.UNAVAILABLE) { alert("New DCR"); } else if (status == IWDCRInfo.ERROR) { alert("Can not set DCR Name"); } else { alert(status + " - That should not have happened!"); }}
I once used setDCRName callback feature + onSave flagging to accomplish something similar. Like that:IWDCRInfo.setDCRName(myDcrName, checkStatus); . . .//---------------------------------------------------------------function checkStatus() {var status = IWDCRInfo.getStatus();if (status == IWDCRInfo.PENDING) {//Check again in 2 secsetTimeout("checkStatus()",2000);}else if (status == IWDCRInfo.AVAILABLE) {if (!confirm("DCR Exists. Do you want to override it?")) {// Restore Original name, Set "Bad Name" Flag to check onSave // and reject, etc...}}else if (status == IWDCRInfo.UNAVAILABLE) {alert("New DCR");}else if (status == IWDCRInfo.ERROR) {alert("Can not set DCR Name");}else {alert(status + " - That should not have happened!");}}
IWDCRInfo.setDCRName(myDcrName, checkStatus); . . .//---------------------------------------------------------------function checkStatus() {var status = IWDCRInfo.getStatus();if (status == IWDCRInfo.PENDING) {//Check again in 2 secsetTimeout("checkStatus()",2000);}else if (status == IWDCRInfo.AVAILABLE) {if (!confirm("DCR Exists. Do you want to override it?")) {// Restore Original name, Set "Bad Name" Flag to check onSave // and reject, etc...}}else if (status == IWDCRInfo.UNAVAILABLE) {alert("New DCR");}else if (status == IWDCRInfo.ERROR) {alert("Can not set DCR Name");}else {alert(status + " - That should not have happened!");}}
Hi Bo,This does not help. Could you please explain tghe functionality of this function.Best Regards,Munish Khanna
Hi Bo,Please ignore. it worked .... Fabulous solution.. Thanks!
Do you understand how/why it works - or are you just happy that someone spoon-fed you working code and satisfied with that?Also - as you seem so fond of saying: "If your issue is resolved, please close the thread" -- however I prefer to make sure the issue is really resolved before doing / requesting that.
hi Adam,Thanks for your nice response. Actually, the issue is not resolved. I was just searching the thread to post back again. Ah yes, I understand how it works and got its reference from the FORM API guide..Neways, heres the deal. I am able to makeout with Bo's code, that there is an existing DCR with the same name but what do we return to the setDCRName function so as to stop it from naming the DCR with the same name..I have tried various things but that does not seem to be working.. Also, as per the FORM API Guide, the callback is done after the DCR save but that does not seem to be happening..The callback is being called before DCR save.. in which case, we should be able to stop the function but how? Any ideas would be highly appreciated.Best Regards,Munish Khanna
Any bidders? Bo, Adam, Andy, anyone?
but what do we return to the setDCRName function so as to stop it from naming the DCR with the same name..
Also, as per the FORM API Guide, the callback is done after the DCR save but that does not seem to be happening..
question to Boris, on your example code in 2nd post of the thread... In a similar case, we've done the "check if file exists" with callserver CGI, rather than the simpler (less code) approach with setDCRName(name, checkStatus).The reason being that in our case, name might include a subdirectory that doesn't exist yet in the /data location. The CGI then creates the missing directories also.I believe we empirically found that in that case, using setDCRName was not working for us (it refused to save file because directory non-existing). Is that your experience also, or did we draw the wrong conclusions?thanks for sharing
You can not "return" anything to setDCRName, it's an asynchronous call. What you can do is (for example) declare a flagto indicate DCR Naming state and use this flag within onSaveValid Event Handler. Something like this:// Declare Globalsvar DCRNamed = false;...// Note that checkStatus() should re-set DCRNamed Flag to true when appropriateIWDCRInfo.setDCRName(myDcrName, checkStatus); ...function handle_saveValid() { if (!DCRNamed) return false; // So far so good, Continue. If everything is fine, return true ....}
what would you like to happen? if you believe the doc, then you can call setDCRName(null) or so. Quote. If path is null, the DCR name is explicitly unset. The callback is not executed if the path is null. The system prompts the user for a DCR name when the Save button is clicked. Unquote.I'm pretty sure the doc says that "The callback executes when the request completes." The request in this case is "the server request for information about that file(name)".So in other words, when you execute setDCRName, an async request is sent to the server to find out if anything by that name exists, etc. When the results are available, the callback is executed.... this is not at all linked to a SAVE event.
I suggest you repost the code you are using (FormAPI + callServer script) if you want any further assistance debugging the behavior you're seeing.
Below is the code. Please let me know if you find something missing. The behaviour basically is that it saves the DCR when I click on Save the second time. The first time though, it does not save the DCR, it still saves the DCRInfo for the DCR..
Note that setTimeout doesn't halt script execution. Rather, it *schedules* the specified call with the given delay.After the call to setTimeout the script immediately continues, with the timer ticking on the background. So, assumingthat the initial value of your dcrNamed flag is null, it is quite possible that (for example) setSaveValidState immediatelyreturns nothing ('return void' if you wish). By the time your user clicks anything again though, scheduled routines wereexecuted, Flag has a value, etc...
Bo, thanks for your nice response. Does this mean that it is just not doable? Any suggestions on improving the code to accomplish the task?Should I just go with the call server then?
With a callserver you could have had this working days ago, is there a particular reason you have avoided it ?
IWEventRegistry.addFormHandler("onSaveValid", allowSave);
IWDCRInfo.setDCRName(dcrName); IWDatacapture.save(dcrName); IWDatacapture.redraw();
I have never had trouble with call server resync. Basically because my original thread stops when the callserver is initiated and then the callback kicks off the save itself
Besides, we both know that's oversimplification. What if setDCRName fails? What if callServer does not make a callbackwithin reasonable time or does not make it at all? What happens if you have few sequential Saves from impatient User?None of that is rocket science of course - but has to be addressed in professional code