My save button uses SSJS with some logic. I want to save datasource, so I use
document1.save();
Script works, but querySave/postSave code is not executed.
Only workaround is to use simple action and divide button event to blocks for "execute script", "Save document (simple action)" and "execute script" (just to return "navigation" string).
Is it possible to save datasource in SSJS and fire qS/pS events?
please try this SSJS code:
var dsName = "document1.DATASOURCE";
var app = facesContext.getApplication();
var ds = app.getVariableResolver().resolveVariable(facesContext, dsName);
ds.save( facesContext, true );
The variable dsName contains the name of your datasource followed by ".DATASOURCE". To use it f.e. with current document, you have to change to "currentDocument.DATASOURCE".
Hope this helps
Sven
Sven what is the difference between your code and currentDocument.save() is something else happening than querysave and postsave?
Related
Good day folks!
I have a call (CSJS) to a JSON-RPC service in my XPage to get the value of a viewScope variable. I use this call to cycle through my field names (dynamically) and validate them.
I'm having trouble figuring out how to get a handle to the datasource (document1 in my case) to which these fields are bound, from the RPC service.
Here's the call:
// Use the JSON-RPC Service to get the number of asset item rows
// from the viewScope variable
var deferred = myRPCService.getScopeVar();
deferred.addCallback(function(result){
alert(result); // <-- viewScope variable value
// get the dynamic field names for the asset items based on row #
var itemname = '';
for (var i = 1; i < result; i++) {
var itemname = 'replace'+(i < 10? '0':'')+ i
if (document1.getItemValueString(itemname) == ""){
// do this
} else{
// do that
}
}
});
I do get back the value of the viewScope variable from the RPC call but I can't get beyond that. Any pointers/examples would be appreciated.
Thanks,
Dan
PS: See my comment below ...
You don't say what calls the JSON-RPC event, so I will guess and say it is a button. You will have to have an additional serverside event set the viewScope variable to the value of document1.getItemValueString(itemname) which you can then retrieve in the RPC.
Your SSJS event code will look something like:
viewScope.result = document1.getItemValueString(itemname);
The additional event can be onmouseover (not recommended) or onkeypress. I assume you are using onclick clientside for this code, you can't use the onclick serverside because this code would need to run prior to your clientside. You will want the viewScope to contain fresh data, hence this suggestion. If the data doesn't need to be fresh, then set it on page load.
Another idea would be to call two RPC's. The first one can set the viewScope variable and the second can use it. The first one won't need a callback, and just calls a java or SSJS function that sets the viewScope. Personally I like this better than my first suggestion.
I need to save serial number of the document in a profile document and here is a code of action Execute Script:
if (document1.isNewNote()){
var pdoc:NotesDocument=database.getProfileDocument("LastNumber","")
var lnm=pdoc.getItemValue("lastNumber")[0];
var inputText6:com.ibm.xsp.component.xp.XspInputText = getComponent("inputText6");
inputText6.setValue(lnm);
pdoc.replaceItemValue("lastNumber",lnm);
pdoc.save();
}
This code is not opening profile document at all. Any thing wrong in the code?
"LastNumber" is the name of the form used to create Profile Document ?
this profile document already exist ?
there are no reader fields in this profile document ?
you have an error on this line : var pdoc:NotesDocument=database.getProfileDocument("LastNumber","") ?
or you have debug it and see that pdoc is null ?
instead of pdoc.getItemValue("lastNumber")[0] you can use pdoc.getItemValueInteger("lastNumber") to get a typed result
I supposed that this field contains a number and you want to increment it
instead of using inputText field you can set value directly with document1.setValue("NumberField", lnm);
I second the caution Per is suggesting. Profile documents can be a beast. You should abstract access to the "next number" into a SSJS function call. Btw. in your code snippet you don't actually increment the last number. Also: if your input text control is bound, go after the data source, not the UI.
A crude way (I would use a managed application bean for better isolation) for a better function could be this:
if(document1.isNewNote() {
document1.setValue("DocumentNumber",applicationTools.getNextNumber());
}
Then in a SSJS library you would have:
var applicationTools = {
"getNextNumber" : function() {
synchronized(applicationScope){
var pdoc:NotesDocument=database.getProfileDocument("LastNumber","");
if (!applicationScope.lastNumber) {
applicationScope.lastNumber = pdoc.getItemValueInteger("lastNumber");
}
applicationScope.lastNumber++;
pdoc.replaceItemValue("lastNumber",applicationScope.lastNumber);
pdoc.save(); //Make sure pdoc is writeable by ALL!!!!
pdoc.recycle();
return applicationScope.lastNumber;
}
},
"someOtherUtility" : function(nameToLookup, departments) {
// more stuff here
}
}
Which, in some way has been asked before, but not for a profile field. Someone still could simply go after the applicationScope.lastNumber variable, which is one of the reasons why I rather use a bean. The other: you could do the saving asynchronously, so it would be faster.
Note: in any case the number generation only works when you have a non-replicating database. But abstracting the function opens the possibility to replace fetching the number from the profile with a call to a central number generator ... or any other mechanism ... without changing your form again.
I am working on CRM 2011.
On Form_onLoad event I am presetting the value of a field.
mdg.PreSetField("address1_line1","Amsterdam");
but after clicking on save button my field address1_line1 is blank.
To check I put a alert on Form_onsave function.
alert("address =" + (Xrm.Page.getAttribute("address1_line1").getValue()));
In alert,I get the value of address1_line1 field but finally address1_line1 is blank.
mdg.PresetField function is as follows
mdg.PreSetField = function(attributeName, value) {
var attribute;
if (attributeName.setSubmitMode) {
attribute = attributeName;
}
else {
attribute = Xrm.Page.getAttribute(attributeName);
}
attribute.setSubmitMode('never');
attribute.setValue(value);
attribute.addOnChange(function() {
attribute.setSubmitMode('always');
});
};
I solved it..
in my custom mdg.PresetField function earlier code was
attribute.setSubmitMode('never');
I changed never to always and now it is working..
mdg.PreSetField("address1_line1","Amsterdam");
This code is not part of the CRM JavaScript API so I assume it's a custom library? Have you added this script to the list of webresources available on the form? Also make sure it comes before the script you are trying to use it in.
Using MonoMac, I have a NSDocument-based application, but I'm needing to create a new NSDocument object when a button is clicked.
For example. I have in another Window I have a NSWindowController and I can do
Controller c = new Controller ();
c.Window.MakeKeyAndOrderFront (this);
thus causing the Window to be loaded that is tied to the controller.
With the NSDocument I guess the controller is built in?
So I'm expecting something like
MyNSDocument doc = new MyNSDocument ("Some Value ");
doc.Window.MakeKeyAndOrderFront (this);
Of course this doesn't work.
Additional info, for example when in the Application if you hit Command + N, then a new Document Window is loaded. This is cool and I basically need the same thing to happen, but when a button is clicked.
Using "File" / "New" or Control + N invokes newDocument: on the application's shared document controller, which is the menu.xib's First Responder.
To do the same programmatically, use NSDocumentController.SharedDocumentController to get the application's shared document controller, then invoke NewDocument () on it (you can pass null as sender):
var controller = (NSDocumentController)NSDocumentController.SharedDocumentController;
controller.NewDocument (null);
I want to be able to add an onBlur/onkeypress/onChange events to all TypeAhead fields on the form rather than have a developer select every one in the Designer client. The only thing I cannot get a handle on is the onChange event.
When the user selects something in the TypeAhead the onChange event is triggered when adding the code directly to the event in the Domino Designer - so I should be able to replicate that capability with code.
If my typeAhead field is called inputText2 I thought I would be able to do the following
var widget = dojo.byId("#{id:inputText2}")
dojo.connect(widget, 'onChange', function (){
alert('1')
});
However this doesn't appear to work...
I tried lowercase onchange
var widget = dojo.byId("#{id:inputText2}")
dojo.connect(widget, 'onchange', function (){
alert('1')
});
no luck there either
I tried
var widget = dijit.byId("#{id:inputText2}");
but that failed to event select the element entirely
So what do I need to do to trigger the onchange event when selecting an option in the typeAhead?
I found a solution.....not ideal but it worked for the moment - not generic though, but a start
Copying the way XPages does it....add this to the page
function view__id1__id2__id31__id50_clientSide_onchange(thisEvent) {
alert('me')
}
and then
dojo.addOnLoad(function(){
XSP.addOnLoad(function() {
XSP.attachEvent("X1","view:_id1:_id2:_id31:inputText2", "onchange", view__id1__id2__id31__id50_clientSide_onchange, false, 2);
});
});
});
X1 must be unique but everything else can be calculated
Thanks to Serdar Basegmez