function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Donny SDonny S 

Formula to get quantity with mixed text and numbers

Hello,

We have thousands of skus that pass over to salesforce. I use shiprush for shipping. I am trying to solve a problem of more than 1 sku in my field.  For example: 12:GARBOO is a common sku, 12 is the quantity and Garboo is the product sku.  Right now I have a formula that will popuilate the ItemQuantity3 custom field with 12 (or any number to the left of the text). This is what I am using and it works great for single sku's.

IF (
ISNUMBER( LEFT( Sku_Shipped_1__c, 2 ) ),
VALUE( LEFT( Sku_Shipped_1__c, 2 ) ),
VALUE( LEFT( Sku_Shipped_1__c, 1 ) )
)

The problem is if a customer orders more than one product it passes through "12:GARBOO, 1:GRTEA, 4:GARCUL". My formula will only take the left nubmer and populate ItemQuantity3. I need the quantity to populate with "17" or what ever numbers are in there. It could be "1:GARBOO, 3:GRENC, 2:RKTVTL" What formula could I use to add only numbers in a field so the latter would pull "6"

Completely stumped.

Thank you in advance :)
Satish_SFDCSatish_SFDC
Because there is specific limit to the number of SKU's which can be added we may not be able to acheive this with a formula.
However, this can be acheived using a before insert trigger.

Regards,
Satish Kumar
GlynAGlynA
Donny,

Satish is right, you will need to write a trigger that runs on "before insert" (and maybe "before update").  The code in the following post will need modification to work in your trigger but it conveys the basic idea.  Let me know if you have any questions.

Glyn Anderson
Sr Developer | System Analyst | ClosedWon | closedwon.com
Certified Developer | Certified Advanced Administrator
Twitter: @GlynAtClosedWon
GlynAGlynA
<pre>
    List<String> list_SKUs = theRecord.Sku_Shipped_1__c.split( ',\\s+' );

    Integer numUnits = 0;
    for ( String sku : list_SKUs )
    {
        String numString = sku.substringBefore( ':' );
        if ( !numString.isNumeric() ) continue;
        numUnits += Integer.valueOf( numString );
    }

    theRecord.ItemQuantity3__c = numUnits;
</pre>
Donny SDonny S
Thank you, I will see what I can do with that. Keep you posted. 
Donny SDonny S
Well, I have no idea what I am doing here. I am getting "Error: Compile Error: unexpected token: List at line 1 column 0". This is my first time looking at apex trigger. I am lost beyond belief. I don't know where to start. I have googled, but it has left me even more confused.