Fusion Manage Forum
Welcome to Autodesk’s Fusion Manage (formerly Fusion 360 Manage) Forum. Share your knowledge, ask questions, and explore popular Fusion Manage topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HTML formatting a field using scripting, not computed field

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Anonymous
1417 Views, 8 Replies

HTML formatting a field using scripting, not computed field

Hi,

I'm trying to change the color of a single line text using scripting instead of the usual 'computed field' approach.  Is this possible?  My equivalent 'computed field' code looks like this;

 

CASE CHECKBOX_1 
WHEN 0 THEN
CASE STATUS_1
WHEN 1 THEN '<span style="text-align:center; line-height:30px; color:green; background:green; width:50px; float:left; height:25px;">GRN</span>'
WHEN 2 THEN '<span style="text-align:center; line-height:30px; color:red; background:red; width:50px; float:left; height:25px;">RED</span>'
WHEN 3 THEN '<span style="text-align:center; line-height:30px; color:yellow; background:yellow; width:50px; float:left; height:25px;">YEL</span>'
WHEN 4 THEN '<span style="text-align:center; line-height:30px; color:blue; background:blue; width:50px; float:left; height:25px;">BLU</span>'
END
ELSE '<span style="text-align:center; line-height:30px; color:black; background:black; width:50px; float:left; height:25px;">BLA</span>'
END

 

This works, however, I have 20 or so fields to apply this logic to.  It would be much simpler to manage using a behavior script to process this as a loop for CHECKBOX and STATUS 1-20.  

 

Thanks for your help.

8 REPLIES 8
Message 2 of 9
gasevsm
in reply to: Anonymous

Try this. http://www.w3schools.com/js/js_switch.asp
In each case statements you would need to assign the new value to the item field with something like this example;

case 1:
item.FIELD_NAME = '<span style="text-align:center; line-height:30px; color:green; background:green; width:50px; float:left; height:25px;">GRN</span>';
break;

You may need to escape some of the " characters but that's the gist of it.

HTH,
--mg

Martin Gasevski | Fusion 360 Team Product Manager
Message 3 of 9
Anonymous
in reply to: gasevsm

Thanks Martin,

I have the case and conditional aspects working, but can't get the HTML formatting to work.  How do I deal with "escaping" characters?  I'm not familiar with that.

 

Looking at just a part of the code...

 

var green = '<span style="text-align:center; line-height:30px; color:green; background:green; width:50px; float:left; height:25px;">GRN</span>';

item.FIELD = green;

 

When the script runs the resulting error is:  "At least one of the input values was set to an illegal value."

 

Any suggestions on getting the HTML to be accepted and execute?

Message 4 of 9
gasevsm
in reply to: Anonymous

I'll give it a try and post a working code once I make it work; it's not a problem ))

Martin Gasevski | Fusion 360 Team Product Manager
Message 5 of 9
Anonymous
in reply to: gasevsm

Thanks Martin!
Message 6 of 9
gasevsm
in reply to: Anonymous

Here's a working example, Ty.

 

1. your field needs to be made into a non-computed field.

2. in your script use this format to set value for each case. eg.

 

    item.TEST_FIELD_FORMATTING = '<span style=\"text-align:center;line-height:30px;color:red;background:red;width:50px;float:left;height:25px;\">RED</span>';

 

 

May be subtle to see, so what I did is:

- ecaped the double-quotes within the script by placing backslash in front of each them

- also removed all whitespaces from the string that is within those (now escaped) double quotes.

 

Yo ucould use this model and the JS switch/case statement to get it finished.  I recommend always setting a switch() { default: } case as well to something recognizable - saves from tons of debugging if none of the case(s) match the expression you're switching on.

 

 I should add, I tested on Chrome. Test the effect of this new javascript-driven formatting of field values in few browsers to see how each handles the HTML character escaping approach. I expect it'd be no problems but let me know if find any incosistency; more than happy to explore an alternate solution 😉 

 

Cheers,


Martin Gasevski | Fusion 360 Team Product Manager
Message 7 of 9
Anonymous
in reply to: gasevsm

Hi Martin, is there a particular field type I should use? I'm using single line text and the result is the field simply says the HTML text and does not format as hoped.

-Ty
Message 8 of 9
gasevsm
in reply to: Anonymous

Hi Ty,

I used SLT field as well; I made sure to edit the field first to clear the computed formula and re-save the field. Only thereafter I used your original html formatting in a action script to make it work as per my example below. Let me know if its still not working after this; we might connect briefly offline to explore the solution together.


Martin Gasevski | Fusion 360 Team Product Manager
Message 9 of 9
gasevsm
in reply to: Anonymous

After meeting together with Ty, we found it was sufficient to use a *read-only* ParagraphWithoutLineBreaks field type to affect its formatting via action script; there wasn't a need for escaping the " characters either in the script code.
An alternate route is to start with a computed SingleLineText (SLT) field containing a set formula, edit the field definition to remove its formula and save, and then use an action script to affect its formatting. The key is a normal SLT wouldn't work - you must start with SLT containing computed formula, then clear it and continue scripting against the field thereafter.
Learn something new every day.)) Cheers..

Martin Gasevski | Fusion 360 Team Product Manager

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report