Skip navigation

JSI Tip 7724. How do I process a multi-line attribute?


NOTE: This tip is superseded by tip 7995.

In tip 7722, I scripted the DSQUERY Filter Extender.

If your query includes a multi-line attribute, like streetAddress, DSQUERY does NOT maintain the report position on the 2nd (and greater) attribute value. For example, if you script:

set query=dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(sAMAccountName=j*))" -attr sAMAccountName streetAddress -limit 0
for /f "Tokens=1* Delims=:" %%q in ('%query% ^|Findstr /l /n /v /c:"*$"') do @echo %%r
The output might look like:
  sAMAccountName    streetAddress
  Jerry             123 Smith Street
  Jennifer          456 Jones Street
Apt. 987
  John              789 Front Street
Notice that Apt. 987, Jennifer's 2nd address line, is not in the streetAddress position.

When you use the DSQFE.bat script, it returns a status of M when it detects the 2nd (nth) line of a multi-line attribute.

NOTE: You must use the object redirecting form of the FOR command.

NOTE: The multi-line attribute should be the last attribute in the query.

NOTE: I have NOT attempted to handle more than one multi-line attribute in a query.

When DSQFE.bat returns a status of M, you can call DSQFEMV.bat to process the multi-line attribute. DSQFEMV.bat will shift the data to the proper column and properly set the Attribute environment variable in your script.

The syntax for using DSQFEMV.bat is:

call DSQFEMV Table Line Attribute

where:

table     is a call directed environment variable that DSQFE.bat used to store attribute information.

line      is a call directed environment variable that contains the multi-line attribute value.

Attribute is the name of the multi-line attribute, like streetAddress.
DSQFEMV.bat contains:
@echo off
if \{%3\}==\{\} goto syntax
set $DSQMVs=                                                                                                                  #
set /a $DSQMVln=0
set /a $DSQFEtp=0
:tloop
call set $DSQFEw=%%%1:~%$DSQFEtp%^,50%%%
if "%$DSQFEw:~0,3%" EQU "###" goto finish
set $DSQFEw=%$DSQFEw: =%
set /a $DSQFEtp=%$DSQFEtp% + 50
call set /a $DSQFEp=10000%%%1:~%$DSQFEtp%^,4%%%%%%10000
set /a $DSQFEtp=%$DSQFEtp% + 4
call set /a $DSQFEl=100%%%1:~%$DSQFEtp%^,2%%%%%%100
set /a $DSQFEtp=%$DSQFEtp% + 2
if /i "%$DSQFEw%" NEQ "%3" goto tloop
call set $DSQMVl=%%$DSQMVs:~0,%$DSQFEp%%%
call set $DSQMVc=%%%2:~0,%$DSQFEl%%%
set $DSQMVl=%$DSQMVl%%$DSQMVc%
call set %$DSQFEw%=%%%2%%###
call set %$DSQFEw%=%%%$DSQFEw%:  =%%%
call set %$DSQFEw%=%%%$DSQFEw%: ###=###%%%
call set %$DSQFEw%="%%%$DSQFEw%:###=%%%"
goto tloop
:finish
set %2=%$DSQMVl%
exit /b 0
:syntax
@echo Syntax:  call DSQFEMV Table Line Attribute
exit /b 1



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish