Why Document properties body value is null in lotus notes? - javascript

Body content is null in document properties showing this sign ""[] instead of content.
Also messsage box lotus script is showing null with getItemValue("Body").
How to resolve this ?
Sub Click(Source As Button)
Dim s As NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim col As NotesDocumentCollection
Set s = New NotesSession
Set db = s.CurrentDatabase
Set col = db.UnprocessedDocuments
Print "Collection Size:"& col.Count
Set doc = col.GetFirstDocument
If doc.HasItem("Body") Then
While Not doc Is Nothing
Dim body As Variant
body = doc.GetItemValue("Body")
Msgbox (body(0))
Set doc = col.GetNextDocument(doc)
Wend
End If
End Sub

Because (usually) Body is a Rich Text field, and these fields are treated differently. See the NotesRichTextItem in the Designer Help.
Starting from your code:
Set s = New NotesSession
Set db = s.CurrentDatabase
Set col = db.UnprocessedDocuments
Print "Collection Size:"& col.Count
Set doc = col.GetFirstDocument
While Not doc Is Nothing
Dim body As Variant
If doc.HasItem("Body") Then
Set body = doc.GetFirstItem("Body") ' now body contains the richtext item'
Msgbox body.UnformattedText
End If
Set doc = col.GetNextDocument(doc)
Wend
Notes should convert the MIME item to rich text for you. If you want to deal with the MIME type, you have to use the NotesMimeHeader and NotesMimeEntity classes. See the Help database, especially the examples on these classes are interesting.

You cannot just reference a NotesRichtTextItem the same way you reference an ordinary NotesItem. A rich text field can contain graphics, tables, fonts, colors, and other things that are not text. It does not matter if it actually does contain those things; it is never a simple array of strings, so Body(0) is not defined. Look up the methods of the NotesRichTextItem class. You will find one called getUnformattedText which will return a simple text representation of the field value.
(There are options for getting the field value as HTML so that you get all the formatting tags, too, but only if the field is really stored as MIME instead of Notes rich text.)

Related

How do I get VBA to submit a javascript form?

I am not sure if I am referencing the button correctly. I keep on getting:
Run-time error '438': Object doesn't support this property or method.
This is what my code looks like at the moment:
Sub russInd()
Dim oButton As Object, HTMLdoc As Object
Dim sht1 As Worksheet, myURL As String
Set ie = CreateObject("InternetExplorer.Application")
Set sht1 = Worksheets("Day 1")
myURL = sht1.Cells(32, 2).Value
ie.navigate myURL
ie.Visible = True
Do Until ie.ReadyState = 4
DoEvents
Loop
'Locate The correct forms and buttons
Set HTMLdoc = ie.document
Set oButton = HTMLdoc.querySelectorAll("a[href='javascript:submitForm(document.forms[0].action);']")
'Check All Checkboxes
HTMLdoc.getElementByID("chkAll").Click
oButton.Click
End Sub
The webpage I am using is:
https://indexcalculator.ftserussell.com/
Here is the webpage code:
I need to click the next button, I did try using
.getElementByID("CtlNavigation_lblControl")
To click the button, however that just skipped over the command, I guess it clicked nothing. Thanks!
querySelectorAll returns a nodelist. You likely want querySelector
Try
HTMLdoc.getElementById("CtlNavigation_lblControl").querySelector("a").Click
or
HTMLdoc.querySelector("CtlNavigation_lblControl a").Click
Set your selector to this: (It's saying look for any image in a parent A element.)
Set oButton = HTMLdoc.querySelectorAll("a > img")
Here is the full code with the modification:
Sub russInd()
Dim oButton As Object, HTMLdoc As Object
Dim sht1 As Worksheet, myURL As String
Set ie = CreateObject("InternetExplorer.Application")
Set sht1 = Worksheets("Day 1")
myURL = sht1.Cells(32, 2).Value
ie.navigate myURL
ie.Visible = True
Do Until ie.ReadyState = 4
DoEvents
Loop
'Locate The correct forms and buttons
Set HTMLdoc = ie.document
Set oButton = HTMLdoc.querySelectorAll("a > img")
'Check All Checkboxes
HTMLdoc.getElementByID("chkAll").Click
oButton.Click
End Sub
Use the following selector as it works across all steps. The number of child a elements within the parent with id Ctlnavigation2_lblControl changes so the following is a robust way to always get what you want across pages.
HTMLdoc.querySelector("#Ctlnavigation2_lblControl [href*=action]").Click
Your error, as partially correct in comments, is that you are trying to use a method of certain node types e.g. a tag element on a nodeList (which is what querySelectorAll returns). It does NOT return a collection. That is a very important distinction in VBA. If you try to For Each, as you would with a collection, over that nodeList Excel will crash.

Xrm.Navigation.openForm not honouring formid

I'm trying to follow the examples found here that explain how to use Xrm.Navigation.openForm method to open a CRM form for a new entity.
My target entity has multiple forms and I'm trying to specify the form ID in the entityFormOptions object as described in the link above. I've copied the relevant text here (with the relevant line in bold):
entityFormOptions
Entity form options for opening the form. The
object contains the following attributes:
cmdbar: (Optional) Boolean. Indicates whether to display the command bar. If you do not specify this parameter, the command bar is displayed by default.
createFromEntity: (Optional) Lookup. Designates a record that will provide default values based on mapped attribute values. The lookup object has the following String properties: entityType, id, and name (optional).
entityId: (Optional) String. ID of the entity record to display the form for.
entityName: (Optional) String. Logical name of the entity to display the form for.
formId: (Optional) String. ID of the form instance to be displayed.
height: (Optional) Number. Height of the form window to be displayed in pixels.
navBar: (Optional) String. Controls whether the navigation bar is displayed and whether application navigation is available using the
areas and subareas defined in the sitemap. Valid values are: "on",
"off", or "entity".
However this doesn't seem to work for me.
The ID of my form is 375DE297-C0AF-4711-A811-5F1663FAE5DA
Here's my code:
var entityFormOptions = {};
entityFormOptions["entityName"] = "contact";
entityFormOptions["formId"] = "375DE297-C0AF-4711-A811-5F1663FAE5DA";
Xrm.Navigation.openForm(entityFormOptions);
The new entity form opens; however it uses the default form, not the specified form.
I am running as a System Administrator and I have confirmed that I have access to all the forms for the specified entity so I don't think it is a form-security issue.
Has anyone tried this method of opening forms in Dynamics 365?
That's looks like mistake in docs or bug in Dynamics.
Previous implementation (v8 and before) took formid in parameters object: https://msdn.microsoft.com/en-us/library/jj602956.aspx#openEntityForm
Although current documentation states that formId must be set in entityFormOptions it isn't actually honoured. But it is honoured when you put it to good old formParameters.
Thus this does the trick:
var entityFormOptions = {};
entityFormOptions["entityName"] = "contact";
var formParameters = {};
formParameters ["formid"] = "375DE297-C0AF-4711-A811-5F1663FAE5DA";
Xrm.Navigation.openForm(entityFormOptions, formParameters);
P.S. Note that lowercase "formid".
This may be a little late but hopefully will help someone else.
The documentation is correct. You can supply formId as shown. You only need to make sure that form is added to the Model Driven App in App Designer (You add the form by checking it on the panel on the right)
var pageInput = {
pageType: "entityrecord",
entityName:"icon_case",
entityId: recordId,
formId: v_formId
};
we can also use the below code to open a particular entity form:
var entityFormOptions = {};
entityFormOptions["entityName"] = "nrw_contact";//Logical name of the entity
entityFormOptions["entityId"] = "nrw_contact_ID"; //ID of the entity record
entityFormOptions["formId"] = "CF8D885B-256D-43E6-8776-CBBB7AA88EF5"; //FormId
Xrm.Navigation.openForm(entityFormOptions);
Please refer this link for more details : https://learn.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/xrm-navigation/openform

Adding custom pdf stamp to document from VBA

I've ran into a problem - I need to add a custom stamp (type of annotation) to a number of .pdf files. I can do it through Actions for Acrobat X Pro, but my clients do not have that license and they still need to do it. The list of files is stored in Excel spreadsheet, so ideally I am looking for a VBA solution. I have came up with the following code :
Option Explicit
Sub code1()
Dim app As Acrobat.AcroApp
Dim pdDoc As Acrobat.CAcroPDDoc
Dim page As Acrobat.CAcroPDPage
Dim recter(3) As Integer 'Array defining the rectangle of the stamp - in real code wil be calculated, simplified for ease of reading
Dim jso As Object
Dim annot As Object
Dim props As Object
Set pdDoc = Nothing
Set app = CreateObject("AcroExch.App")
Set pdDoc = CreateObject("AcroExch.PDDoc")
recter(0) = 100
recter(1) = 100
recter(2) = 350
recter(3) = 350
pdDoc.Open ("C:\Users\maxim_s\Desktop\Code_1\test1.pdf")
Set jso = pdDoc.GetJSObject
If Not jso Is Nothing Then
Set page = pdDoc.AcquirePage(0)
Set annot = jso.AddAnnot
Set props = annot.getprops
props.page = 0
props.Type = "Stamp"
props.AP = "#eIXuM60ZXCv0sI-vxFqvlD" 'this line throws an error. The string is correct name of the stamp I want to add
props.rect = recter
annot.setProps props
If pdDoc.Save(PDSaveFull, "C:\Users\maxim_s\Desktop\Code_1\test123.pdf") = False Then
MsgBox "fail"
pdDoc.Close
Else
MsgBox "success"
pdDoc.Close
End If
End If
End Sub
The problem is with the setprops and getprops procedures - it seems that at the moment when annotation is created (jso.AddAnnot) it does not posses the AP property, which is the name of the stamp I want to add. If I set the property Type= "Stamp" first and then try to specify the AP, the result is that one of the default stamps is added and it's AP is renamed to my custom stamps' AP. Also note, that if I launch acrobat and use the code below, the proper stamp is added:
this.addAnnot({page:0,type:"Stamp",rect:[100,100,350,350],AP:"#eIXuM60ZXCv0sI-vxFqvlD"})
If there is a way to execute this Javascript from VBA inside of the PDDoc object, that will solve the problem, but so far I have failed.
You can use "ExecuteThisJavaScript" from the AForm Api. Short example:
Set AForm = CreateObject("AFormAut.App")
AForm.Fields.ExecuteThisJavaScript "var x = this.numPages; app.alert(x);"
It has the advantage that you don't need to translate the js examples into jso code. If you search for ExecuteThisJavaScript you will get some more and longer examples.
Good luck, reinhard
In...
props.Type = "Stamp"
The type should be lower case. But if the pure JavaScript is working from the console, you might consider just executing the string using the jso.

VBA getting data seen in Javascript tooltip

I am trying to extract the data that a javascript tooltip displays, but have no idea how to do it. I thought maybe an XMLHTTP request needs to be sent to the server, but honestly I am not sure. Below is the JS tooltip code to show and hide the tool tip. Is there something else I have to look for other than this to help me get the information that the tooltip shows and put that data in an excel sheet? I really would like some help from beginning to end on this, because I honestly do not know how to start it. Thank you very much.
< a href="javascript:gotopage('D35555')" on mouse over="ajax_showTooltip('D35555','DATA_PAGE',this);return false" on mouse out="ajax_hideTooltip()" >
Here is a link below to Mr. Excel, that I posted the question on, but I do no think they understand what I am trying to do. Thank you
http://www.mrexcel.com/forum/excel-questions/827332-parsing-javascript-%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A-text.html
Try something like that to read parent file
Function GetHTML(URL As String) As String
Dim HTML As String
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", URL, False
.Send
GetHTML = .ResponseText
End With
End Function
From Reading HTML file in VBA Excel
Then find anchor tags as shown in code below
Private Sub SomeMethod()
Dim URL As String, Result As String
URL = "http://localhost/ajax-tooltip/ajax-tooltip.html"
Result = GetHTML(URL)
Dim Document As Object
Set Document = New HTMLDocument
Dim HTMLElement As IHTMLElement
Document.Open
Document.write Result
Document.Close
Dim ElementCollection As IHTMLElementCollection
Set ElementCollection = Document.getElementsByTagName("a")
Dim mouseOverValue As String
For Each HTMLElement In ElementCollection
If Not IsNull(HTMLElement.getAttribute("onmouseover")) Then
mouseOverValue = HTMLElement.getAttribute("onmouseover")
If InStr(mouseOverValue, "ajax_showTooltip") Then
MsgBox ("Find your page here and read its HTML: " + mouseOverValue)
End If
End If
Next HTMLElement
End Sub
Parse mouseOverValue to get value of tooltip page and call GetHTML again for tooltip page

Logging in to Website with Excel-VBA

Thanks for taking a look at the question. I am trying to log into a website through VBA. This may have already been answered, but I'm having trouble finding something that works. I've done internet automation with VBA before. I've even used it to log into different sites before, but this one is giving me an issue. I've tried getElementByID, getElementByTagName, etc, but nothing seems to be able to populate the "loginName" and "password" text boxes.
The website is https://vfo.frontier.com/
What I found odd is that when I would go to inspect an element through GoogleChrome Browser it wouldn't take me to the text box I had selected.
Thanks so much in advance. Sorry for any errors, I'm still pretty new to VBA and this is my first post to the site.
The code I have now is below:
Sub FVFO()
Dim IE As InternetExplorerMedium
Dim uRl As String
Dim UserN As Object 'MSHTML.IHTMLElement
Dim PW As Object 'MSHTML.IHTMLElement
Set IE = New InternetExplorerMedium
uRl = "https://vfo.frontier.com/"
With IE
.navigate uRl
.Visible = True
End With
' loop until the page finishes loading
Do While IE.Busy
Loop
' enter username and password in textboxes
Set UserN = IE.document.getElementsByName("loginName")
If Not UserN Is Nothing Then
' fill in first element named "username", assumed to be the login name field
UserN.Value = "login name"
End If
Set PW = IE.document.getElementsByName("password")
' password
If Not PW Is Nothing Then
' fill in first element named "password", assumed to be the password field
PW.Value = "my Password"
End If
End Sub
GetElementsByName returns a collection of elements -- even if there is only one element, it is still a collection. So, you need to index it correctly. Assuming the first instance of such an element Name is the appropriate one:
UserN(0).Value = "login name"
And likewise:
PW(0).Value = "my password"
Results:
Tested in InternetExplorer.Application (I don't know what InternetExplorerMedium is...) using late-binding (although that should not matter):
Dim IE as Object
Set IE = CreateObject("InternetExplorer.Application")
The following also works using the getElementByID method, which returns a single element (because the id is unique):
Set UserN = IE.document.getElementByID("loginName")
If Not UserN Is Nothing Then
' fill in first element named "username", assumed to be the login name field
UserN.Value = "blargh"
End If
Set PW = IE.document.getElementByID("password")
' password
If Not PW Is Nothing Then
' fill in first element named "password", assumed to be the password field
PW.Value = "my Password"
End If

Categories

Resources