How to get the old value in an OnChange function in LotusScript? - lotus-notes

I have a field called StartDate, and the field's OnChange function has a loop similar to this:
Set doc = view.GetFirstDocument
While Not (doc Is Nothing)
If (doc.Username = somevalue) Then
If (doc.StartDate(0) = specialdate) Then
' Do something here
End if
End if
Set doc = view.GetNextDocument(doc)
Wend
My problem is that doc.StartDate holds the new value of the field but I want the old one. How do I get the field's previous value? Basically I need to compare the field's old value with its new value.

Define a global variable like "StartDateOld" in form's (Global) / (Declarations).
Assign the value of field "StartDate" to this variable in PostOpen event.
You can use the old value in variable "StartDateOld" in OnChange event then.
Don't forget to set the changed value to "StartDateOld" at the end of OnChange event's code.
This works for a document in edit mode. I don't really understand what you want to achieve with your code running through the view though...

Related

Setter method is not called when the text is deleted in an InputText field bounded to a property in Oracle MAF

I have the following inputText field in MAF.
< amx:inputText value="#{bindings.searchCivilID.inputValue}" label="civil id" id = "it1">
The setter setSearchCivilID() is called each time when i change the text in the field. (like - from "1" to "12").
But when I try to delete the text or totally remove the text , the setter method is not called and hence the previous value is retained in the property.
Can you guys help me out in this?
Thanks,
Haleem.
Tick the check box:" Notify listeners when property changes" while generating generating get() and set() . so when the value of the field changes it will fire the method propertyChangeSupport.firePropertyChange("<your_variable_name>",oldValue,newValue)

fieldChanged function in netsuite

Field Changed Function
If the value in a text field is changed to the same value (example: old value = "ABC", new value = "ABC"), will the script
Field Changed Function fire or not?
nlapiSetFieldValue
Some additional information:
FieldName:
String - the name of the field being set
value: String - the value the field is being set to
firefieldchanged: Boolen - if true then the fieldchange script for
that field is executed. (Only available in Client SuiteScript)
Sets the value of the given field.
This API can be used during beforeLoad scripts to initialize field scripts on new records or non-stored fields.
nlapiSetFieldValue is available only in Client and User Event SuiteScripts.
Whenever you are changing the value of an textfield, you will call the fieldChanged event even if you are staying with the same name as you had before.
If you are asking about the Client Side script event Field Change, if I recall correctly this will only trigger when the user has changed the value of the field in the UI. But this event can also be triggered by the nlapiSetFieldValue and nlapiSetCurrentLineItemValue if the fireFieldChange parameter is set to True.

Approve file without modifying Modified date and editor values using Client Object Model

http://social.technet.microsoft.com/Forums/ar/sharepoint2010programming/thread/b60495ee-29be-4aa0-935e-484abce6b9d2 explains how to approve a file using Client Object Model. Doing so, the 'modified date' and 'modified by' values gets changed (which is obvious).
But, I have a requirement to approve the File without changing those field values.
Can it be done?
If I first publish the file and then update the above-mentioned fields, then the version gets incremented, which is undesirable.
Thanks and Regards,
Arjabh
Instead of using .update() use .systemupdate() - this bypasses modifying the date last I checked.
ListItem item = get the item here
item["Modified"] = modifiedDate; // new modified date
FieldUserValue newModifiedBy = new FieldUserValue();
newModifiedBy.LookupId = modifiedBy; // your LookupId value
item["Editor"] = newModifiedBy;
item.Update();
$ctx.ExecuteQuery();

Update computed fields without validating

I have a form with a field ItemNumber that has a validation forumla that ensures a value is entered.
In lotusscript i create a new document with that form, then depending on the value of a different computed field ItemProductFamilyType (computed based on a field of another doc) i might want to populate ItemNumber.
The issue i have is that if i look at the value of ItemProductFamilyType it's blank, because it's not yet been computed. It'll only have a value once a field is updated, then it's the document refreshed/re-computed.
I'm trying to use ComputeWithForm for this (with the raiseError parameter being a 1 or 0), however because of validation formulas on other fields it's not letting me.
So, how can i get computed fields to update their value without checking/erroring on validation formulas?
Try adding a validation control field. So, add a field called "runValidation". It's computed for display, as it's only required for UI form events handling. It's formula is straight forward
#ThisValue or runValidation
In the QueryRecalc event or whenever you want to set the value for ItemProductFamilyType set it to "1".
Sub Queryrecalc(Source As Notesuidocument, Continue As Variant)
On Error Goto errHandle
Dim doc As notesDocument
Set doc = source.Document
' go populate your fields like ItemProductFamilyType
doc.runValidation = "1"
Exit Sub
errHandle:
Messagebox Lsi_info(2) + " : " + Str(Err) + " - " + Error(Err) + ", at line " + Str(Erl)
Exit Sub
End Sub
The same idea works in the translation formula of ItemProductFamilyType
Field runValidation := "1";
#thisValue;
In the validation formula for ItemNumber include the "runValidation" field to manage when the field should validate.
#if(runValidation="1";#if(#trim(#ThisValue)="";#Failure("Enter value");#Success);#Success)
You should now be able safely call a Source.Refresh method without inadvertently triggering validation rules until the data is ready.
I'm not sure if there's a Lotus Notes-specific workaround for this, but one trick that would work in any system is to have another test in your validation formulas. Instead of saying just #If(FieldName != ""; #Failure; #Success), add another condition that you can control like #If(DoValidation = "Yes" & FieldName != ""; #Failure; #Success). Then you can control validation by controlling the value of the DoValidation item.
I often add #IsDocBeingSaved to the condition so that validation only fires when you are saving the document:
#If(#IsDocBeingSaved & FieldName != ""; #Failure; #Success)
Another thought, given the potential that the ComputeWithForm method is unreliable: Why not check the value in the other document using LotusScript? In fact, you could call that same code from the QueryRecalc event and update the ItemProductFamilyType item, sparing you the need to duplicate code.

Can I set the default value of a custom list column to be a new Guid?

I tried setting the defaultvalue property of the field to Guid.NewGuid() but every item created has the same guid so I guess the Guid.NewGuid() is being stored as the default rather than being run each time.
Is the only way to achieve this to add an event handler to the list for OnAdded?
I'm assuming you're using a Single Line of Text field for this. The standard default for such a field is always a constant, you can't assign a variable or function via the object model. All that would do is assign the static result of that particular call of the function.
While text fields can support a calculated default value, it uses the same functions that are in Calculated columns, which do not support random numbers.
Your best bet is to use an Event Handler, I would recommend ItemAdding over ItemAdded as well. You'd be assigning to properties.AfterProperties["fieldname"] instead of field.DefaultValue, of course.
If you are creating the field through code and setting the field.DefaultValue = Guid.NewGuid(), this will run the Guid.NewGuid() and store the returned Guid as the default
It is the equlivant of running the folowing code:
Guid newGuid = Guid.NewGuid();
string newGuidString = newGuid.ToString();
field.DefaultValue = newGuidString;
I dont know of any method you can use to set the field to generate a new Guid on item creation other than using an Event handler.
It should be posable to genrate a random number using the field.DefaultValue = "RANDBETWEEN(10,20)"; but i have not tested this

Resources