Jump to content
Salesforce and other SMB Solutions are coming soon. ×

Beginner help - how do I make script to change text formatting?


nishimark

Recommended Posts

I've fiddled around with scripting and searched the web, but still can't make it work.

 

I want to change the color (from black to red) and formatting (from plain to bold) of text in the Name field of a found set if the name is "Mark". How do I do that? Thanks in advance.

Link to comment
Share on other sites

not sure what exactly you are after, but the appropriate functions are

TextColor (text ; RGB ( x; y ; z ) ) and TextStyleAdd ( text ; styles ).

see the help viewer for details. If you need help with implementing, you need to be more specific as to the context of your question. e.g. how is the found set created? is "mark" the only name you wish to highlight? etc.

Link to comment
Share on other sites

Thanks for the reply. Yes, i've found the functions in Help, but can't seem to figure out how to implement them.

 

I using 8.5 to produce a dispatch like schedule for sending various wedding pastors to various wedding chapels. So, I have such fields as date, time, hotel, and pastor, as well as others. I usually view them in a list-like view. In the pastor field is a drop-down field of about 10 different names. I would like to be able to change the text formatting on one of those pastors names to make it more easily noticed in a list of events.

 

The most ideal situation would be the ability to toggle on and off the text formatting. Also, if I could apply such formatting to each individual pastor name that would be a nice option.

 

Is that enough information? I appreciate the help.

Link to comment
Share on other sites

you could put a calculated field on top of the name field. Give it a background color of choice and lock it from user access, so that if the user clicks in the field, he will select the name field underneath (to edit it). assuming your select field is a global field (gSelect) (it should be for this to work):

gToggle is a global number which is either 0 (null) or 1. If it is 1, the formatting will be applied. If not, then the field will always be plain / black formatted.

HighlightName = calc, text result (unstored) =

Case 
Case 
([b]gToggle[/b] ;
(
  [b]Name[/b] = [b]gSelect[/b] ; 
  TextStyleAdd ( TextColor ( [b]Name[/b] ; RGB (250 ; 0 ; 90 ) ) ; Bold ) ;
  TextStyleAdd ( TextColor ( [b]Name[/b] ; RGB (0 ; 0 ; 0 ) ) ; Plain ) 
 );
TextStyleAdd ( TextColor ( [b]Name[/b] ; RGB (0 ; 0 ; 0 ) ) ; Plain ) 
)

 

gToggle can be set using a set field script step connected to a button:

 

set field [ table::gToggle ; case ( gToggle ; 0 ; 1 ) ]

 

Also, if I could apply such formatting to each individual pastor name that would be a nice option.
I don't understand what you want. you mean blue for Frank, red for Peter and purple for Steve?

 

Please note that global fields in a networked environment will reset to the original value after closing the file. The original value is the last value the field held before the file was put on the network. If you want these values to be set dynamically or according to user prefs, you need a utility table to read and store these values from at startup / closedown.

 

edited

Link to comment
Share on other sites

You can use just the data entry field:

 

The text field has a calculation option.

 

Open define fields, click on the checkbox.

 

Insert this formula* changing values where capitalized.

 

Click OK

 

Click OK

 

Enter Browse mode.

 

Now change the values in your text field and watch the color change.

 

Your next question is gonna be....

 

*Sample Formula

 

Case(

PatternCount(Account Name ;"Jack") >0;TextColor ( Account Name; RGB ( 255 ; 0 ; 0 ) );

PatternCount(Account Name ;"Marc") >0;TextColor (Account Name; RGB ( 0;0;255 ) );

PatternCount(Privilege Set Name ;"Production") >0;TextColor (Account Name; RGB ( 100;100;100 ) );

PatternCount(Privilege Set Name ;"Manager") >0;TextColor (Account Name; RGB ( 200;200;200 ) );

PatternCount(Privilege Set Name ;"Sales") >0;TextColor (Account Name; RGB ( 10;10;10 ) );

TextColor ( Account Name ; RGB ( 0 ; 200 ; 0 ) )

)

Link to comment
Share on other sites

Your next question is gonna be....

how you gonna update an auto-enter calculation across the found set without scripting? OP wants to highlight text based on a selection criterium, not on some record-specific status.

Link to comment
Share on other sites

Overlooked the found set part.

 

In that case do not use the calculation in the field definitions.

 

Obviously create a script using the case I supplied but adjusted for your conditions and apply that script.

 

The calc will automatically apply the color based on the contents of various fields or default to black or whatever.

 

You can use the Replace Field function and apply it to all selected records and avoid and complicated loops.

 

Find

Replace Field using Jack's Case calculation

...

Cheer, applaud, buy everyone a new car!

Link to comment
Share on other sites

for clarity, there now are two methods presented:

1 - create a calc field which will update automatically for each record

2 - create an script and do a replace field contents by calc

 

depending on circumstance, either may be the better choice. 1 makes for some overhead (namely, and extra unstored field); 2 will require a triggered update which will take some time depending on the size of the found set. triggering the update upon selecting a value (in this case, the name of a pastor) will require a plugin like zippscript - or a button next to the select field says "update".

 

personally in this case i'd stick with 1 even if it means I got to keep driving my 12 yr old ford. but be glad to be corrected and get a new model, something less burdensome for the climate.

 

but the interesting question here really is: when to use a calc and when to use an auto-enter field in the circumstance that you need user-editable content to be recalculated sometimes.

Link to comment
Share on other sites

  • 2 weeks later...

I've come in late to this discussion, and I understand it has mainly been to do with text formatting functions in scriptmaker. But at a simpler level I have found the conditional text formatting function in v9 to be very useful. It allows me, for example, to print envelopes with the word "confidential" in red if the envelope is to contain an invoice. Otherwise the word is printed in white - that is, invisible.

Link to comment
Share on other sites

In rereading it seems he wants to format the text of a specific record.

 

So, add an extra field to the view and format it as a checkbox and when that checkbox is checked, then have the calc activate:

 

If cb = 1

 

use my calc above

 

else

 

remove formatting

 

end if

 

Or you could make the field a button and activate the script when the button is clicked.

Link to comment
Share on other sites



×
×
  • Create New...

Important Information

Terms of Use