Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
FormApi: onSaveNameSpecified and setDCRName
RonaldV
Hi,
i'm trying to check and modify the name of a dcr (replace whitespace and at a .dcr extension) at the onSaveNameSpecified-event. However calling the IWDCRInfo.setDCRName function has NO result. Meaning the dcr is simply saved by the name the user entered.
Any hints?
Here is my js-code:
var version = '20050722';
var showdebug = 1;
IWEventRegistry.addFormHandler("onSaveNameSpecified", checkDcrName);
function checkDcrName(path) {
if (IWDCRInfo.getDCRName() != '') {
//already set, do nothing
debug('Name already set: ' + IWDCRInfo.getDCRName());
} else {
var dirOrig, nameOrig;
var re = new RegExp('(.*)/([^/]+)$');
if (path.match(re)) {
dirOrig = RegExp.$1;
nameOrig = RegExp.$2;
}
debug(nameOrig);
//replace all whitespaces by _
var nameNew = nameOrig.replace(/ /g, '_');
debug(nameNew);
//take off any trailing dots
nameNew = nameNew.replace(/\.*$/g, '');
//add .dcr extension if not already done
if (! nameNew.match(/\.dcr$/)) {
nameNew += '.dcr';
}
//alert if something changed
if (nameOrig != nameNew) {
IWDCRInfo.setDCRName(dirOrig + '/' + nameNew, wait());
alert('Dcr-naam gewijzigd in "' + nameNew + '".');
}
}
return true;
}
function wait() {
var cnt = 0;
while (IWDCRInfo.getStatus() == IWDCRInfo.PENDING && cnt < 10) {
alert(IWDCRInfo.getStatus());
cnt++;
}
alert('Status: ' + IWDCRInfo.getStatus() + ': ' + IWDCRInfo.getDCRName ());
}
function debug(msg) {
if (showdebug) {alert(msg);}
}
debug('checkDcrName.js version ' + version + ' loaded');
TS65 Sp1
Win2k Sp4
OD602
Find more posts tagged with
Comments
RonaldV
Can somebody teach the people at Iwov how to write proper documentation?
Here is the story. Calling IWDCRInfo.setDCRName will do something but will NOT save the dcr under this new name. So you will have to call IWDatacapture.save() after setDCRName AND then prevent Teamsite from saving the same dcr twice by returning false to the event. (Who has thought of this procedure??)
Anyway some working sample code. Good luck with it:
IWEventRegistry.addFormHandler("onSaveNameSpecified", checkDcrName);
function checkDcrName(path) {
if (IWDCRInfo.getDCRName() != '') {
//already set, do nothing
debug('Name already set: ' + IWDCRInfo.getDCRName());
} else {
var pathNew = '/your/new/name.dcr';
debug('Setting name to ' + pathNew);
IWDCRInfo.setDCRName(pathNew);
IWDatacapture.save();
//at this point the dcr is allready saved so we MUST prevent a second save
return false;
}
return true;
}
TS65 Sp1
Win2k Sp4
OD602
cliffhanger
Interesting finding.
Just shooting in the dark here...I think what you are experiencing is happening because if you call .setDCRName explicitly from your checkDCRName and
return true immediately, then the form's save event implicitly calls setDCRName() for the initial path assigned to the form(the one that you get in your
onSaveNameSpecified handler). This second call to the setDCRName overwrites the still pending setDCRName that you explicitly requested from
checkDCRName.
The reason having a IWDatacapture.save() and a return false works because by returning false you are cancelling the form's .setDCRName request. And when IWDatacapture.save() again gets to checkDCRName() it gets into the first conditional(if block) and returns true, to save continues with your path specified.
Just a possible explanation......
RonaldV
Thanks, I think you are right there.
TS65 Sp1
Win2k Sp4
OD602