Type Mismatch - Lotusscript - lotus-notes

I don't know where I'm wrong but I kept on getting "Type mismatch" error
Here is the original code
Dim policy As New Policy
Dim policyDocument As NotesDocument
Set policyDocument = p_baseManager.base_policyDocument
policy.formName = policyDocument.Getitemvalue("Form")(0) //Had type mismatch error on this line
policy.universalId = policyDocument.Universalid
policy.formX = policyDocument.Getitemvalue("FormX")(0)
I tried to modify it a bit to display some of the values
Dim policy As New Policy
Dim policyDocument As NotesDocument
Set policyDocument = p_baseManager.base_policyDocument
Print "universal id = " + policyDocument.Universalid
Print "FORM NAME = " + policy.formName
policy.formName = "FormName"
Print "FORM NAME = " + policy.formName
policy.formName = policyDocument.Getitemvalue("Form")(0) // still getting type mismatch
policy.universalId = policyDocument.Universalid
policy.formX = policyDocument.Getitemvalue("FormX")(0)
Thank you!

Adding error handling is the best way to find out where the error is occurring. The type mismatch will be data-specific, so it's going to be difficult to troubleshoot without having access to the environment. The best library for error handling in LotusScript is beyond all doubt OpenLog.

Ok, lets analyze this using your "DEBUG"- Code. We have two custom classes that we know nothing about:
Class name: Policy
Instance: policy
and
Class name: ???
Instance: p_baseManager
Then we have the line that throws the error:
policy.formName = policyDocument.Getitemvalue("Form")(0)
From your Test- Line
policy.formName = "FormName"
we know, that policy.formName accepts a String as an input and that the left side of our erroneous line does throw an error in itself.
Now, if we have a "Type mismatch" that means that our right part of the assignment does not return a string.
If p_baseManager.base_policyDocument did not return a valid NotesDocument, then we would get an Object variable not set in that line --> We can conclude, that policyDocument is a valid NotesDocument and not Nothing.
Now lets look at GetItemValue("Form"): It returns an Empty String, if the document does not contain an item named "Form": An empty String still is a String --> No Type Mismatch in that case.
The only possibility, that policyDocument.Getitemvalue("Form")(0) does not return a String, is, if the item is present but contains a number or a date value...
So: What to do now?
First of all: Are you SURE that the error is in that line (did you use Debugger)?
Second: Use the debugger to find out the value of the Form- Item of your PolicyDocument
Third: As mentioned by Paul Stephen Withers: Use error handling to EXACTLY identify the error line, error code and error.

Related

Error: "Cannot find 'get' method for string class."

I'm coding with GUIDE. I want to get data input from handles.edit1,...handles.edit8 and save to variable handles.in(1,1),...handles.in(1,8). My code is below and I get an error:
Cannot find 'get' method for string class.
edit = ["handles.edit1","handles.edit2","handles.edit3","hanles.edit4","handles.edit5","handles.edit6","handles.edit7","handles.edit8"]
for i = 1:1:8
handles.in(1,i) = str2num(get(edit(1,i),'string'));
end
you should change
edit = ["handles.edit1","handles.edit2","handles.edit3","hanles.edit4","handles.edit5","handles.edit6","handles.edit7","handles.edit8"]
to
edit = [handles.edit1,handles.edit2,handles.edit3,hanles.edit4,handles.edit5,handles.edit6,handles.edit7,handles.edit8];

Checking what a value is in SSJS

I have this block of code in SSJS that I'm doing some field validation stuff:
thisDoc is a NoteXspDocument
fld = the name of a field
var thisValue = thisDoc.getValue(fld);
print("Check Text = " + thisValue);
print("Is is a Date " + (thisValue === Date))
when I run it the log has this:
Check Text = 09/10/15 12:00 PM
Is is a Date false
In this code I do not know what the datatype is of the fld which is a field name. I check the backend document and get the NotesItem.Type() and this field is of type text 1280 in the backend, but the NotesXspDocument has a date. I need to determine what the data type is thisValue sure acts like a NotesDateTime object, but I'm doing something wrong somewhere.
I think the issue might be the difference between a NotesDateTime and a java.util.Date but they drive me up the wall.
Further Edit --
The problem is that I have an Array of field names var Fields:Array that I then loop through and get fld = Fields[n] so when I get the value of the field it could be anything Text, Date, Number so when I do var thisValue = thisDoc.getValue(fld) or thisDoc.getItemValue(fld) I need to figure out what kind of value I have. I guess I could put the getItem..... inside a try until I find one that works but that seems like a less than optimum solution.
Try instanceof Date.class. What you've got is not checking the data type of thisValue against the underlying class, instead it's checking the object itself.
Because the field that I am retrieving can be just about anything I use
var thisValue = thisdoc.getValue(fld);
i had a lot of trouble then determining what kind of data I had. It could be a null Date/Number/String So the first thing I did was find out what the backend data type was:
var thisItem:NotesItem = thisDoc.getDocument().getFirstItem(fld);
var type:Integer = thisItem.getType()
This helps somewhat if the field has been previously set, but if it is a new document or the field has not received a value yet it will be type 1280 or text and probably null.
So my fisrt test is for null or "". then it becomes a bit tougher because I need to test for some values. In all my comboboxs I add the text "--- Select ?????" as the first item in the list so I tried to get a substring of "---" but because of variance in the datatype I needed to put that in a try:
try{
if (thisValue.substring(0,3) == "---"){
print("have null Prefix");
rtn = false;
errMsg.push("The field " + fld + " is a Required Field please enter a value");
break;
}catch(e){ etc
I then wrapped the various other datatype tests in trys and now I have it working.
Might be a better way but this works.
Use .getItemValue() to return a vector array, then test the data type. You can also try .getItemValueString() to return a text string or .getItemValueDate() or .getItemValueDateTime() to return date/time.
Since getItemValue() returns an array, use subscript to get the first element:
var thisValue = thisDoc.getItemValue(fld);
var thisIsDate = (thisValue[0] instanceof Date);
print("Check Text = " + thisValue[0]);
print("Is this a Date ? " + thisIsDate;

Getting "Value does not fall within the expected range" when creating a new discussion with CSOM

I'm using the SharePoint 2013 client object model.
I'm getting a Microsoft.SharePoint.Client.ServerException that says: "Value does not fall within the expected range" when running _context.ExecuteQuery(). The code works as long as I comment out the statement entry["Author"] = authorValue;:
entry["Body"] = post.Body;
entry["Created"] = post.Created;
entry["Modified"] = post.Modified;
FieldUserValue authorValue = new FieldUserValue();
User author = _context.Web.EnsureUser("Mr. X");
_context.Load(author);
_context.ExecuteQuery();
authorValue.LookupId = author.Id;
entry["Author"] = authorValue;
entry.Update();
_context.ExecuteQuery();
"Author" is a valid field name. I also read about increasing "List View Lookup Threshold" to a value of 20 in http://dotnetfollower.com/wordpress/2012/05/sharepoint-value-does-not-fall-within-the-expected-range-exception-in-spfieldmap-getcolumnnumber/. But that value is already set to 5000.
I also checked the value of entry["Author"] without setting it explicitly (entry["Author"] = authorValue commented out) by adding this two statements:
_context.Load(entry);
_context.ExecuteQuery();
It is of type Microsoft.SharePoint.Client.FieldUserValue and it's LookupId property value is equal to authorValue.LookupId.
What did I miss?

eval() is not working properly

I get the following error while trying to evaluate a predicate in a a4solution:
Fatal error in /some/path at line 9 column 2: Field "field
(A/Attribute <: type)" is not bound to a legal value during
translation.
Here is the code at the origin of the error:
for(ExprVar a : solution.getAllAtoms()){
// additional checks are here to assure that a is of an "appropriate type"
solution.eval(predicate.call(a));
}
In my vain attempts to solve this problem by myself, I read from this source http://code.google.com/p/alloy4eclipse/issues/detail?id=86 that the way the solution has been read from the file might cause this problem.
But the source doesn't give further details.
I have created my solution object as follows :
XMLNode xml = new XMLNode(new StringReader(source.getFileContent()));
this.solution = A4SolutionReader.read(new ArrayList<Sig>(), xml);
Thank you for your support
The problem was that the expression to be evaluated (predicate.call(a)) was drawn from one CompModule object (namely the predicate function was taken from there) while the solution object, against which the expression was evaluated, was not obtained from the same CompModule, but was read from a file.
Generally, when reading a solution from an xml file, to be on the safe side, it is recommended to reread and reconstruct everything from that xml file, e.g.,
XMLNode xmlNode = new XMLNode(new File("my_solution.xml"));
String alloySourceFilename = xmlNode.iterator().next().getAttribute("filename");
Module module = CompUtil.parseEverything_fromFile(rep, null, alloySourceFilename);
A4Solution ans = A4SolutionReader.read(module.getAllReachableSigs(), xmlNode);
In some cases it suffices to just pass the sigs from the original CompModule to the reconstructed solution:
XMLNode xmlNode = new XMLNode(new File("my_solution.xml"));
A4Solution ans = A4SolutionReader.read(originalModule.getAllReachableSigs(), xmlNode);

VBA Passing Object into another Objects Collection

I have a set of owners, who each have their own set of opportunities.
I have two class modules, ClmOpportunity which has a bunch of properties, and ClmOwner which has a single name property and a Collection storing ClmOpportunity Objects:
Public name As Variant
Private opps As New collection
Public Function addOpportunity(opp As ClmOpportunity)
opp.ID = opps.Count + 1
opps.Add opp, opps.Count + 1
End Function
These owner objects are also being stored in a collection in my main module. When I try to use the function addOpportunity as shown below:
Dim item As New ClmOpportunity
item.name = "test"
owners.item(overallOwner).addOpportunity (item)
I get the error:
"object doesn't support this property or method"
I am quite new to VBA and I don't understand why this is, I am passing in a ClmOpportunity, so it should be fine right?
Any help would be greatly appreciated!
You don't use parentheses if there's no return value...
owners.item(overallOwner).addOpportunity item
...then you'll get a "type mismatch" error because a collection expects a string value as a key, so you'll need to adjust your addOpportunity function (which should probably be a Sub if you don't intend adding a returned value)

Resources