Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
FormAPI how to check existing DCR
cc96ai
In my datacapture.cfg, the DCR name will depend on the field "ProgramCode",
However, if we input same ProgramCode , it will overwrite the existing one.
Can FormAPI check the file exists or not, then it will pop out a alert window to choice overwrite or not.
I try to use "IWDCRInfo.getFileSize()", but it seems it is not working .
function init() {
IWEventRegistry.addFormHandler("OnSaveValid", setName);
}
function setName (){
var name = IWDatacapture.getItem("/ProgramCode").getValue();
name = trimString(name);
IWDCRInfo.setDCRName(name);
return true;
}
Thanks
--------------------------------------------
TS 6.1 W2K3
OpenDeploy 6.0
CC Pro/Std
Find more posts tagged with
Comments
Migrateduser
You could build a script that will do this -- register an onSave event which does a callServer. The callServer can call a script that checks for the existence of the DCR. Based on the result of the script, your function will return either true or false with an alert.
Dave
Current Environment(s):
(1) TS 6.5 on W2K3
(2) TS 6.1 SP1 on W2K3
By the way, I miss Unix terribly.
kalyani
Check the The Organisation User Script in Sample User Scripts in tst6.5.formapi.pdf or see the code below .
//The init()function is executed at the end of this script.
//It register registers the event handlers.
function init(){
//Register a function to handle Save.
IWEventRegistry.addFormHandler("onSave",saveHandler);
//Register a function to change the DCR name based on the department.
IWEventRegistry.addItemHandler("/organization/department","onItemChange",departmentHandler);
//Call the departmentHandler()on load to set the initial status.
departmentHandler(IWDatacapture.getItem("/organization/department"));
}
//The departmentHandler()function sets the DCR named based on the currently selected department.
function departmentHandler(item){
//Get the department name.
var department =item.getOptions()[item.getValue()].value;
//Is the current DCR name different from the department?
var dcrName =IWDCRInfo.getDCRName();
if (dcrName !=department){
//Yes -set the DCR name to the department name.This is an
//asynchronous call -but at this time we are not interested
//in the return values,so we specify a null callback
//function.
IWDCRInfo.setDCRName(department,null);
}
}
//This function is called when user saves the form.It sets the DCR
//name,if not set already.It also ensures that someone else's
//changes are not being inadvertently overwritten (which can happen
//in shared workareas).
function saveHandler(){
var result;
//Before calling IWDCRInfo methods,always check the status.
switch (IWDCRInfo.getStatus()){
case IWDCRInfo.AVAILABLE:
//We have information on this DCR avaiable,so we can
//check a few extra things.
if (IWDCRInfo.isModifiedInWA() && IWDCRInfo.getOwner()!=IWDatacapture.getUser()){
//If it's been changed by another user,prompt to confirm.
var message ="DCR was modified by another user.";
message +="\nFile details are:\n";
message +="\nSize:"+IWDCRInfo.getFileSize();
message +="\nOwner:"+IWDCRInfo.getOwner();
message +="\nLast modified:"+
IWDCRInfo.getModificationDate();
message +="\n \nDo you still want to save?";
result =confirm(message);
}else {
//Otherwise,we're in great shape.
result =true;
}
break;
case IWDCRInfo.PENDING:
//The query for information on this DCR hasn't returned yet.
//Let the user decide if they want to proceed with the save.
var message ="The form will be saved to the file:\""+
IWDCRInfo.getDCRName()+"\".\n \n";
message +="The system is still waiting for information about thisfile.\n \n";
message +="You may Cancel and try again in a few moments,\n";
message +="or press OK to continue with the save."
result =confirm(message);
break;
case IWDCRInfo.UNAVAILABLE:
default:
//There's no information available on the current DCR name,
//most likely because it doesn't exist.Proceed with the save.
result =true;
}
return result;
}
//Call the initialization routine on load.
IWEventRegistry.addFormHandler("onFormInit",init);
cc96ai
I try to use formAPI which's on the document
however, it always goes into "case IWDCRInfo.PENDING:"
no matter , I create a new DCR or edit the existing one
any idea
Thanks
--------------------------------------------
TS 6.1 W2K3
OpenDeploy 6.0
CC Pro/Std
cc96ai
How can I just return True / False from the ipl ?
from the document, I only can see that you can set the variable back to DCR field,, but can we set the value back into JS variable in DCR ?
<html>
<head>
<script language="javascript">
// Get handle to the FormAPI/userscript frame.
api = parent.getScriptFrame();
// Set the city and state.
api.IWDatacapture.getItem("/city").setValue("Sunnyvale");
api.IWDatacapture.getItem("/state").setValue("CA");
</script>
</head>
<body>
</body>
</html>
--------------------------------------------
TS 6.1 W2K3
OpenDeploy 6.0
CC Pro/Std
Adam Stoller
I think what you need to look at is callServer() - which allows you to call a program on the server-side to perform some form of checking on the value of the data in the DCT/DCR and then that program can interact with the FormAPI layer of the caller to set the value or to popup an alert box of some sort.
I'd suggest RTFM and search DevNet for examples -- along with some caveats, like the fact that callServer() is asynchronous which makes working with it a bit more difficult than might be suspected at first glance.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
cc96ai
any idea on always return IWDCRInfo.PENDING when using IWDCRInfo.getStatus()
--------------------------------------------
TS 6.1 W2K3
OpenDeploy 6.0
CC Pro/Std