To find a particular word written in a string type field in AX 2012? - dynamics-ax-2009

Is it possible in AX 2012 to find a particular word/words written in a string type field in AX 2012 table or form.
e.g, I have a field named Memo in my table named test. In that field I have a written a text as:
Hello,
We need to confirm you that your < mobileNumber > is successfully attached with your account no. < Account >.
Now, I need to find all texts written inside tags "<" and ">".
Furthermore I require to replace these texts according to my need.
Please tell if its possible in AX 2012 or if there is any other option that I can opt to fulfill my need.

You can find every occurence of "<" and ">" using the strScan function
http://msdn.microsoft.com/en-US/library/aa866529(v=ax.50).aspx
Use that to find the location of the "<"s and matching ">"
Use SubStr http://msdn.microsoft.com/en-US/library/aa677836(v=ax.50).aspx to find what is between "<" and ">", and apply your replacement based on that (using strPoke http://msdn.microsoft.com/en-US/library/aa850123(v=ax.50).aspx)
A useful AX2009 string class that utiliseses these methods and that may be of some help can be found here
http://axgeek.blogspot.co.uk/2010/04/string-function-class.html , it should not take much effort to convert to 2012.
Of particular interest to you is the replace method.
However it may be simpler to have the memo as "Hello, We need to confirm you that your %1 is successfully attached with your account no. %2.", and to insert the values using strFmt
http://www.axaptapedia.com/index.php?title=StrFmt
Of course the .Net String.Replace method is also available.
see http://msdn.microsoft.com/en-us/library/cc584291.aspx and http://msdn.microsoft.com/en-us/library/system.string.replace.aspx

Related

Scripting Word from vbs

I'm trying to get Word to fill in cells in a table. The script works when run as a macro from within Word, but fails when saved as a .vbs file and double-clicked, or run with wscript. This is a part of it.
set obj = GetObject(,"Word.Application)
With obj
With .Selection
MsgBox .text
If (.Information(wdWithInTable) = True) Then
.Collapse Direction:=wdCollapseStart
tCols = .Tables(1).Columns.Count
tRow = .Information(wdStartOfRangeRowNumber)
tCol = .Information(wdStartOfRangeColumnNumber)
For I = 2 To 5
.Tables(1).Cell(tRow, I).Range.Text = "fred" & Str(I)
Next
` now make new row
For I = 1 To tCols - tCol + 1
.MoveRight unit:=wdCell
Next
End If
End With
End With
I have three problems. First, it won't compile unless I comment out the .Collapse and .MoveRight lines. Second, although the MsgBox .text displays the selected text, I get "out of range" errors if I try to access any .Information property.
I'm sure I'm missing something very simple: I usually write software for Macs, and I'd do this using AppleScript. This is my first attempt at getting anything done under Windows.
VBScript and VBA are different languages.
They are a bit similar, but not very. Moreover, VBScript is not like AppleScript; it doesn't let you easily interface with running programs.
The interfaces you'll get from VBScript can behave subtly differently in VBA and VBScript. However, I think you've got two problems here:
:= is invalid syntax in VBScript; you'll need to find an alternative way of calling the function. Try just using positional arguments.
You've no guarantee that this will open the expected file; there could be another instance of Word that it's interacting with instead.
Since your code is not running within the Word environment it would require a reference to the Word object library in order to use enumeration constants (those things that start with wd).
VBScript, however, cannot work with references, which means the only possibility is to use the long value equivalents of the enumerations. You'll find these in the Word Language References. Simplest to use is probably the Object Browser in Word's VBA Editor. (In Word: Alt+F11 to open the VBA Editor; F2 to start the Object Browser; type in the term in the "Search" box, click on the term, then look in the bottom bar.)
The code in the question uses, for example:
wdWithInTable
wdCollapseStart
wdStartOfRangeRowNumber
wdStartOfRangeColumnNumber
wdCell
The reason you get various kinds of errors depends on where these are used.
Also, VBScript can't used named parameters such as Unit:=. Any parameters must be passed in comma-delimited format, if there's more than one, in the order specified by the method or property. If there are optional parameters you don't want to use these should be left "blank":
MethodName parameter, parameter, , , parameter

How to format CRM "Date Only" field to string with Freemarker?

Im trying to build a email template with Freemarker/Clickdimensions plugin in CRM 2013. I have a "Date only" field on an entity which for example contains the date 2017-04-17. I want this date to show as the following: Monday 17 april.
This is done with Freemarker and I have tried the following:
<#assign x = Recipient.field_booking.field_scheduleddate?time>
${x?string.full}
This doesnt seem to work. Im not getting any result at all, just an empty line.
Does anyone know what could be wrong?
I will assume that field_scheduleddate is a string (not a java.util.Date).
At ?time FreeMarker should throw and exception saying something like that the string doesn't follow the expected pattern. I suspect the framework you are using catches and suppresses that exception (which makes using FreeMarker much much harder). Check the logs, maybe it's there.
You want to deal with a date-only value there, hence you should use ?date, as ?time is for time-only values. Also, field_scheduleddate apparently uses ISO 8601 format, so unless the date_format configuration setting is set to ISO, you will have to use ?date.iso (supported since FreeMarker 2.3.21).
As of printing the date, ?string.full should work, but usually you should set date_format globally to the format you prefer, and then you can simply write ${x}.
(Also note that #assign is unnecessary above, as you can put arbitrarily complex expression inside ${}.)

Summing XML Data in MSWord Mail Merge

I have a report card written in Word that uses an XML file for its input. In the XML file, if a student remains in the same section all three trimesters there will be one node for that class; if they change sections at the trimester they'll have one node for each section. The nodes look something like this (greatly simplified):
<ReportCardSectionFB Abs1="2" Abs2="11" CourseID="ELMATH1" CourseTitle="Math" PeriodStart="3" TeacherName="Jones, Jennifer" TermCode="Year" SectionID="ELMATH1-4" />
<ReportCardSectionFB Abs1="1.50" Abs2="6" CourseID="ELMATH1" CourseTitle="Math" PeriodStart="3" TeacherName="Smith, Tina" TermCode="Year" SectionID="ELMATH1-3" />
There is no indicator within the XML as to which trimester the node belongs to.
In the Word document, we're pulling the absence data with the following mail merge command:
{MERGEFIELD "ReportCardSectionFB[#PeriodStart='3']/ #Abs1" \# 0.# \* MERGEFORMAT }
That's not working in this situation: it only gets the absence data from the first node it comes across, i.e.: 2.0. Is there a way to get the sum of #Abs1 for all period 3 classes, i.e.: 3.5? If not, is there a way to only get the last #Abs1 for period 3, i.e.: 1.5?
I recommend you to use this 3rd party product, which can use xml as input and is capable of merging it with MS Word template. I is also much more powerful than the built-in Word's mail merge. You can see some examples here.
You could also try summing the absences in Synergy - there's a new checkbox under AttDef1, 2, etc. that adds up all the absences for the data range - Include all day data for the entire date range regardless of section enrollment or section timeframe. That way the absences should be the same for each section, if that works for your district.
You can also try the SET function in Word to nest the MERGEFIELDS as bookmarks and use the Word operator functions to then add the bookmarks.

Rounding Numbers in Actuate

Using Actuate eReport Designer Professional 9 SErvice Pack 3 Fix 2
I am attempting to set a text control's ValueExp property to display a string consisting of a division result concatenated with some static text. I want the division result to display as an integer if there is no remainder. Otherwise, I want only 1 decimal place.
There will be conditional logic involved, but I will be able to handle that. What I am really looking for is, using the Expression Builder only, can I format numbers. For example, how would I get the expression, 5/3 & " text" to display 1.7 text? This guess,
round(5/3, 1) & " text"
threw errors for "illegal variable use (round)" and "operator not found for these types"
From Dominique's answer, this effort:
BirtMath.round(5/3, 1)
resulted in an illegal variable use on BirtMath.
Try this:
BirtMath.round(5/3, 1) + " text"
(tested on BIRT Eclipse designer, this should be the same with actuate professional designer)
What finally got the job done was:
Format(5/3, "##.#") & " text"
Dominique's answer refers to BIRT, which is a completely different technology/product.
If you want to display a numeric value with special formatting, a Text Control is not the best choice here. Instead, you should use a numeric control of the appropriate type (for example, a Double Control) and either override the GetText() method of that control to handle the display formatting or use Conditional Formatting. The reason this is a better solution is that data search and export will not work properly with a Text Control.
Note that you can use a format pattern like this: "#,##0 \T\e\x\t" instead of concatenating the string; this technique is needed when you are using Conditional Formatting.
Personally, I would prefer you to use Conditional Formatting, because I put a lot of effort into designing that feature of e.Reports, and I'd like to see more people using it. :) But overriding GetText() is probably easier in your specific situation, due to the need to do more complex string manipulation to eliminate the trailing decimals.
I want to add that with BIRT, you can also format the text in a more 'graphic' way, without the need for SQL ... in case it is useful to someone ...
Select the Object - Properties - Format Number - You choose the Format
there is variety for each case and in addition to adding the custom format.
Of course, it is everyone's decision to how format the text, and it is always good to know how it is done in different ways!

Best practice to show custom fields on dynpro?

I am assigned to implement new custom fields. The possible entries have to be selected from a value table. The value table holds the key and a explaning text. The dynpro is build like that:
Input for new field (zzfield) | Output-only field for explaining text. (zzfield_text)
What I want my dynpro to do:
a) Show text in output field based on entered key
b) Update text after ENTER/SAVE from user
c) Update text directly after a new key has been selected from the value table
My current solution is this:
" in the dynpro
PROCESS BEFORE OUTPUT.
MODULE GET_ZZFIELD_TEXT.
" in the module
DATA: zzfield_text TYPE string.
SELECT SINGLE text
FROM value_table
INTO zzfield_text
WHERE zzfield = mara-zzfield.
This works well for the cases a) and b) I have listed above. However, beeing in a PBO, it does not work for case c). My colleage suggested to use something like this:
" in the dynpro
PROCESS AFTER INPUT.
field: zzfield MODULE get_zzfield_text_pai ON REQUEST.
I can not duplicate my code in the module get_zzfield_text_pai, because the of the DATA declaration of zzfield_text. It is reported to be unknown in the PAI (besides it is already defined in the PBO module) but it is also reported to be duplicated if I declare it again in the PAI. Further, I dont know how to implement new global fields into my function group. Using another include creates again issues of that zzfield_text beeing unknown.
In general, I am not happy about my solution and would be very thankfull for each suggestion about how to code this feature.

Resources